package com.geologyoa.persist;

import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;

import net.sf.json.JSONObject;

import com.geologyoa.commons.JdbcUtil;
import com.geologyoa.commons.commUtils;
import com.geologyoa.domain.Cjdw01;
import com.geologyoa.domain.Dwqk01;
import com.geologyoa.domain.Wpdj01;
import com.geologyoa.domain.Wpfj01;
import com.geologyoa.domain.Xmfj01;
import com.geologyoa.domain.Xmqk01;
import com.geologyoa.domain.Xmqk01New;
import com.geologyoa.domain.ZHD01;
import com.geologyoa.domain.Zjpf01;
import com.geologyoa.domain.xmqkQueryObj;

public class Xmqk01DaoImpl implements Xmqk01Dao {
	Connection conn = null;
	PreparedStatement ps = null;
	Statement st = null;
	ResultSet rs = null;
	public Boolean AddXmqk(Xmqk01 xmqk01) {
		Boolean flag =false;
		   conn=JdbcUtil.getConnection();
		   String sql = "";
		  sql = "insert into xmqk01 values(oa_seq.nextval,?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?,?,?,?,?," +
		  		" ?,?,?,?,?,?)";
			try {
				ps = conn.prepareStatement(sql);
				ps.setString(1, xmqk01.getXmqk01002());
				ps.setString(2, xmqk01.getXmqk01003());
				ps.setString(3, xmqk01.getXmqk01004());
				ps.setString(4, xmqk01.getXmqk01005());
				ps.setString(5, xmqk01.getXmqk01006());
				ps.setString(6, xmqk01.getXmqk01007());
				ps.setString(7, xmqk01.getXmqk01008());
				ps.setString(8, xmqk01.getXmqk01009());
				ps.setString(9, xmqk01.getXmqk01010());
				ps.setString(10, xmqk01.getXmqk01011());
				ps.setString(11,xmqk01.getXmqk01012());
				ps.setString(12,xmqk01.getXmqk01013());
				ps.setString(13,xmqk01.getXmqk01014());
				ps.setString(14,xmqk01.getXmqk01015());
				ps.setString(15,xmqk01.getXmqk01016());
				ps.setDouble(16,xmqk01.getXmqk01017());
				ps.setDouble(17,xmqk01.getXmqk01018());
				ps.setDouble(18,xmqk01.getXmqk01019());
				ps.setDouble(19,xmqk01.getXmqk01020());
				ps.setDouble(20,xmqk01.getXmqk01021());
				ps.setDouble(21,xmqk01.getXmqk01022());
				ps.setDouble(22,xmqk01.getXmqk01023());
				ps.setDouble(23,xmqk01.getXmqk01024());
				ps.setString(24,xmqk01.getXmqk01025());
				ps.setString(25,xmqk01.getXmqk01026());
				ps.setString(26,xmqk01.getXmqk01027());
				ps.setString(27,xmqk01.getXmqk01028());
				ps.setString(28,xmqk01.getXmqk01029());
				ps.setString(29,xmqk01.getXmqk01030());
				ps.setString(30,xmqk01.getXmqk01031());
				ps.setString(31,xmqk01.getXmqk01032());
				ps.setString(32,xmqk01.getXmqk01033());
				ps.setString(33,xmqk01.getXmqk01034());
				ps.setString(34,xmqk01.getXmqk01035());
				ps.setString(35,xmqk01.getXmqk01036());
				ps.setDouble(36,xmqk01.getXmqk01037());
				ps.setString(37,xmqk01.getXmqk01038());
				ps.setString(38,xmqk01.getXmqk01039());
				ps.setString(39,xmqk01.getXmqk01040());
				ps.setString(40,xmqk01.getXmqk01041());
				ps.setString(41,xmqk01.getXmqk01042());
				ps.setDouble(42,xmqk01.getXmqk01043());
				ps.setDouble(43,xmqk01.getXmqk01044());
				ps.setDouble(44,xmqk01.getXmqk01045());
				ps.setDouble(45,xmqk01.getXmqk01046());
				ps.setDouble(46,xmqk01.getXmqk01047());
				ps.setString(47,xmqk01.getXmqk01048());
				ps.setString(48,xmqk01.getXmqk01049());
				ps.setString(49,xmqk01.getXmqk01050());
				ps.setString(50,xmqk01.getXmqk01051());
				ps.setString(51,xmqk01.getXmqk01052());
				ps.setString(52,xmqk01.getXmqk01053());
				ps.setString(53,xmqk01.getXmqk01054());
				ps.setString(54,xmqk01.getXmqk01055());
				ps.setString(55,xmqk01.getXmqk01056());
				ps.setString(56,xmqk01.getXmqk01057());
				ps.setString(57,xmqk01.getXmqk01058());
				ps.setString(58,xmqk01.getXmqk01059());
				ps.setDouble(59,xmqk01.getXmqk01060());
				ps.setString(60,xmqk01.getXmqk01061());
				ps.setString(61,xmqk01.getXmqk01062());
				ps.setString(62,xmqk01.getXmqk01063());
				ps.setString(63,xmqk01.getXmqk01064());
				ps.setString(64,xmqk01.getXmqk01065());
				ps.setString(65,xmqk01.getXmqk01066());
				ps.setString(66,xmqk01.getXmqk01067());
				ps.setString(67,xmqk01.getXmqk01068());
				ps.setString(68,xmqk01.getXmqk01069());
				ps.setString(69,xmqk01.getXmqk01070());
				ps.setString(70,xmqk01.getXmqk01071());
				ps.setString(71,xmqk01.getXmqk01072());
				ps.setDouble(72,xmqk01.getXmqk01073());
				ps.setString(73,xmqk01.getXmqk01074());
				ps.setString(74,xmqk01.getXmqk01075());
				ps.setString(75,xmqk01.getXmqk01076());
				ps.setString(76,xmqk01.getXmqk01077());
				ps.setString(77,xmqk01.getXmqk01078());
				ps.setString(78,xmqk01.getXmqk01079());
				ps.setString(79,xmqk01.getXmqk01080());
				ps.setString(80,xmqk01.getXmqk01081());
				ps.setString(81,xmqk01.getXmqk01082());
				ps.setString(82,xmqk01.getXmqk01083());
				ps.setString(83,xmqk01.getXmqk01084());
				ps.setString(84,xmqk01.getXmqk01085());
				ps.setDouble(85,xmqk01.getXmqk01086());
				ps.setString(86,xmqk01.getXmqk01087());
				ps.setString(87,xmqk01.getXmqk01088());
				ps.setString(88,xmqk01.getXmqk01089());
				ps.setString(89,xmqk01.getXmqk01090());
				ps.setString(90,xmqk01.getXmqk01091());
				ps.setString(91,xmqk01.getXmqk01092());
				ps.setString(92,xmqk01.getXmqk01093());
				ps.setString(93,xmqk01.getXmqk01094());
				ps.setString(94,xmqk01.getXmqk01095());
				ps.setString(95,xmqk01.getXmqk01096());
				ps.setString(96,xmqk01.getXmqk01097());
				ps.setString(97,xmqk01.getXmqk01098());
				ps.setDouble(98,xmqk01.getXmqk01099());
				ps.setString(99,xmqk01.getXmqk01100());
				ps.setString(100,xmqk01.getXmqk01101());
				ps.setString(101,xmqk01.getXmqk01102());
				ps.setString(102,xmqk01.getXmqk01103());
				ps.setString(103,xmqk01.getXmqk01104());
				ps.setString(104,xmqk01.getXmqk01105());
				ps.setString(105,xmqk01.getXmqk01106());
				ps.setString(106,xmqk01.getXmqk01107());
				ps.setString(107,xmqk01.getXmqk01108());
				ps.setString(108,xmqk01.getXmqk01109());
				ps.setString(109,xmqk01.getXmqk01110());
				ps.setString(110,xmqk01.getXmqk01111());
				ps.setDouble(111,xmqk01.getXmqk01112());
				ps.setString(112,xmqk01.getXmqk01113());
				ps.setString(113,xmqk01.getXmqk01114());
				ps.setString(114,xmqk01.getXmqk01115());
				ps.setString(115,xmqk01.getXmqk01116());
				ps.setString(116,xmqk01.getXmqk01117());
				ps.setString(117,xmqk01.getXmqk01118());
				ps.setString(118,xmqk01.getXmqk01119());
				ps.setString(119,xmqk01.getXmqk01120());
				ps.setString(120,xmqk01.getXmqk01121());
				ps.setString(121,xmqk01.getXmqk01122());
				ps.setString(122,xmqk01.getXmqk01123());
				ps.setString(123,xmqk01.getXmqk01124());
				ps.setString(124,xmqk01.getXmqk01125());
				ps.setString(125, xmqk01.getXmqk01126());
				ps.setString(126, xmqk01.getXmqk01127());
				ps.setInt(127, xmqk01.getXmqk01128());
				ps.setInt(128, xmqk01.getXmqk01129());
				ps.setInt(129, xmqk01.getXmqk01130());
				ps.setInt(130, xmqk01.getXmqk01131());
				ps.setString(131,xmqk01.getXmqk01132());
				ps.setInt(132, xmqk01.getXmqk01133());
				ps.setInt(133, xmqk01.getXmqk01134());
				ps.setString(134,xmqk01.getXmqk01135());
				ps.setString(135,xmqk01.getXmqk01136());
				ps.setString(136,xmqk01.getXmqk01137());
				int number=ps.executeUpdate();
				if(number>0)
				{
					flag=true;
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return flag;
	}
	public List<Xmqk01> SerachXmqk01(String xmqk01003, String xmqk01005,
			String xmqk01006, String minfy, String maxfy, String minjgtime,
			String maxjgtime,String xmqk01009) {
		Xmqk01 xmqk01=null;
		List<Xmqk01> xmqk01List=new ArrayList<Xmqk01>();
		   conn=JdbcUtil.getConnection();
		   StringBuffer sql = new StringBuffer();	
		   sql.append("select * from xmqk01 where 1=1");
		      if(!xmqk01003.equals(""))
		      {
		    	  sql.append(" and xmqk01003 like'%"+xmqk01003+"%'");  
		      }
		    	  
		      if(!xmqk01005.equals(""))
		      {
		    	  sql.append(" and xmqk01005 ='"+xmqk01005+"'");  
		      }
		      if(!xmqk01006.equals(""))
		      {
		    	  sql.append(" and xmqk01006 ='"+xmqk01006+"'");  
		      }if(!minfy.equals(""))
		      {
		    	  sql.append(" and xmqk01019>'"+minfy+"' and xmqk01019<'"+maxfy+"'");
		      }
		      if(!minjgtime.equals(""))
		      {
		    	  sql.append(" and xmqk01119>'"+minjgtime+"' and xmqk01119<'"+maxjgtime+"'");
		      }
			try {
				ps = conn.prepareStatement(sql.toString());
				rs=ps.executeQuery();
				while(rs.next())
				{
					xmqk01=new Xmqk01();
					xmqk01.setXmqk01001(Integer.parseInt(rs.getString("xmqk01001")));
					xmqk01.setXmqk01002(rs.getString("xmqk01002"));
					xmqk01.setXmqk01003(rs.getString("xmqk01003"));
					xmqk01.setXmqk01004(rs.getString("xmqk01004")==null?"":rs.getString("xmqk01004"));
					xmqk01.setXmqk01005(rs.getString("xmqk01005"));
					xmqk01.setXmqk01006(rs.getString("xmqk01006"));
					xmqk01.setXmqk01007(rs.getString("xmqk01007"));
					// modify by cuiyi 20130501 批准单位  根据id从 单位基本情况里面去取
					String tmpDwqk0101 = rs.getString("xmqk01008")==null?"":rs.getString("xmqk01008");
					int dwqk01Int = getInteger(tmpDwqk0101);
					String sqlTmp= "select * from dwqk01 where   dwqk0101 ='"+dwqk01Int+"'";
					PreparedStatement psTmp = conn.prepareStatement(sqlTmp);
					ResultSet rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01008(rsTmp.getString("dwqk0103"));
					}else{
						xmqk01.setXmqk01008(rs.getString("xmqk01008"));//批准单位
					}
					// modify by cuiyi 20130501 承担单位  根据id从 单位基本情况里面去取
					
					String cddwName = xmqk01009!=null&&!xmqk01009.equals("")?xmqk01009:"";//项目承担单位名称 模糊匹配
					String subSql = " and dwqk0103 like '%"+cddwName+"%'";
					tmpDwqk0101 = rs.getString("xmqk01009")==null?"":rs.getString("xmqk01009");
					dwqk01Int = getInteger(tmpDwqk0101);
					sqlTmp= "select * from dwqk01 where   dwqk0101 ='"+dwqk01Int+"'"+subSql;
					
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01009(rsTmp.getString("dwqk0103"));
					}else{
						xmqk01.setXmqk01009(rs.getString("xmqk01009"));//承担单位
					}
					xmqk01.setXmqk01010(rs.getString("xmqk01010"));//承担单位资质
					xmqk01.setXmqk01011(rs.getString("xmqk01011"));//
					/// modify by cuiyi 20130501  招投标代理机构及资质     根据id从 单位基本情况和资质表里面去取
					tmpDwqk0101 = rs.getString("xmqk01012")==null?"":rs.getString("xmqk01012");
					dwqk01Int = getInteger(tmpDwqk0101);
					sqlTmp= "select * from dwqk01,dwzz01 where   dwqk0101=dwzz0102 and dwzz0102 ='"+dwqk01Int+"' and dwzz0104='招投标'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01012(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01013("招投标代理"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01012(rs.getString("xmqk01012"));//招投标代理机构
						xmqk01.setXmqk01013(rs.getString("xmqk01013"));//代理机构资质
					}
					//////////////////
					xmqk01.setXmqk01014(rs.getString("xmqk01014"));
					xmqk01.setXmqk01015(rs.getString("xmqk01015"));
					xmqk01.setXmqk01016(rs.getString("xmqk01016"));
					xmqk01.setXmqk01017(rs.getDouble("xmqk01017"));
					xmqk01.setXmqk01018(rs.getDouble("xmqk01018"));
					xmqk01.setXmqk01019(rs.getDouble("xmqk01019"));
					xmqk01.setXmqk01020(rs.getDouble("xmqk01020"));
					xmqk01.setXmqk01021(rs.getDouble("xmqk01021"));
					xmqk01.setXmqk01022(rs.getDouble("xmqk01022"));
					xmqk01.setXmqk01023(rs.getDouble("xmqk01023"));
					xmqk01.setXmqk01024(rs.getDouble("xmqk01024"));
					xmqk01.setXmqk01025(rs.getString("xmqk01025"));
					xmqk01.setXmqk01026(rs.getString("xmqk01026"));
					xmqk01.setXmqk01027(rs.getString("xmqk01027"));
					xmqk01.setXmqk01028(rs.getString("xmqk01028"));
					xmqk01.setXmqk01029(rs.getString("xmqk01029"));
					///对 勘察单位进行单位名称和资质的判别   如果在单位表里面不存在  则使用原始记录
					sqlTmp= "select * from dwqk01,dwzz01 where   dwqk0101=dwzz0102 and dwzz0102 ='"+rs.getString("xmqk01030")+"' and dwzz0104='勘查'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01030(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01031("勘察"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01030(rs.getString("xmqk01030"));
						xmqk01.setXmqk01031(rs.getString("xmqk01031"));
					}
					xmqk01.setXmqk01032(rs.getString("xmqk01032"));
					xmqk01.setXmqk01033(rs.getString("xmqk01033"));
					/// modify by cuiyi 20130501  招投标代理机构及资质     根据id从 单位基本情况和资质表里面去取
					tmpDwqk0101 = rs.getString("xmqk01034")==null?"":rs.getString("xmqk01034");
					dwqk01Int = getInteger(tmpDwqk0101);
					sqlTmp= "select * from dwqk01,dwzz01 where   dwqk0101=dwzz0102 and dwzz0102 ='"+dwqk01Int+"' and dwzz0104='招投标'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01034(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01035("招投标代理"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01034(rs.getString("xmqk01034"));
						xmqk01.setXmqk01035(rs.getString("xmqk01035"));
					}
					
					xmqk01.setXmqk01036(rs.getString("xmqk01036"));
					xmqk01.setXmqk01037(rs.getDouble("xmqk01037"));
					xmqk01.setXmqk01038(rs.getString("xmqk01038"));
					xmqk01.setXmqk01039(rs.getString("xmqk01039"));
					xmqk01.setXmqk01040(rs.getString("xmqk01040"));
					xmqk01.setXmqk01041(rs.getString("xmqk01041"));
					xmqk01.setXmqk01042(rs.getString("xmqk01041"));
					xmqk01.setXmqk01043(rs.getDouble("xmqk01043"));
					xmqk01.setXmqk01044(rs.getDouble("xmqk01044"));
					xmqk01.setXmqk01045(rs.getDouble("xmqk01045"));
					xmqk01.setXmqk01046(rs.getDouble("xmqk01046"));
					xmqk01.setXmqk01047(rs.getDouble("xmqk01047"));
					xmqk01.setXmqk01048(rs.getString("xmqk01048"));
					xmqk01.setXmqk01049(rs.getString("xmqk01049"));
					xmqk01.setXmqk01050(rs.getString("xmqk01050"));
					xmqk01.setXmqk01051(rs.getString("xmqk01051"));
					xmqk01.setXmqk01052(rs.getString("xmqk01052"));
					///对 可研编制单位进行单位名称和资质的判别   如果在单位表里面不存在  则使用原始记录
					sqlTmp= "select * from dwqk01,dwzz01 where  dwqk0101=dwzz0102 and dwzz0102 ='"+rs.getString("xmqk01053")+"' and dwzz0104='可研'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01053(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01054("可研"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01053(rs.getString("xmqk01053"));
						xmqk01.setXmqk01054(rs.getString("xmqk01054"));
					}
					xmqk01.setXmqk01055(rs.getString("xmqk01055"));
					xmqk01.setXmqk01056(rs.getString("xmqk01056"));
					/// modify by cuiyi 20130501  招投标代理机构及资质     根据id从 单位基本情况和资质表里面去取
					tmpDwqk0101 = rs.getString("xmqk01057")==null?"":rs.getString("xmqk01057");
					dwqk01Int = getInteger(tmpDwqk0101);
					sqlTmp= "select * from dwqk01,dwzz01 where   dwqk0101=dwzz0102 and dwzz0102 ='"+dwqk01Int+"' and dwzz0104='招投标'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01057(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01058("招投标代理"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01057(rs.getString("xmqk01057"));
						xmqk01.setXmqk01058(rs.getString("xmqk01058"));
					}
					
					xmqk01.setXmqk01059(rs.getString("xmqk01059"));
					xmqk01.setXmqk01060(rs.getDouble("xmqk01060"));
					xmqk01.setXmqk01061(rs.getString("xmqk01061"));
					xmqk01.setXmqk01062(rs.getString("xmqk01062"));
					xmqk01.setXmqk01063(rs.getString("xmqk01063"));
					xmqk01.setXmqk01064(rs.getString("xmqk01064"));
					xmqk01.setXmqk01065(rs.getString("xmqk01065"));
					
					///对 设计单位进行单位名称和资质的判别   如果在单位表里面不存在  则使用原始记录
					sqlTmp= "select * from dwqk01,dwzz01 where  dwqk0101=dwzz0102 and dwzz0102 ='"+rs.getString("xmqk01066")+"' and dwzz0104='设计'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01066(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01067("设计"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01066(rs.getString("xmqk01066"));
						xmqk01.setXmqk01067(rs.getString("xmqk01067"));
					}
					xmqk01.setXmqk01068(rs.getString("xmqk01068"));
					xmqk01.setXmqk01069(rs.getString("xmqk01069"));
					/// modify by cuiyi 20130501  招投标代理机构及资质     根据id从 单位基本情况和资质表里面去取
					tmpDwqk0101 = rs.getString("xmqk01070")==null?"":rs.getString("xmqk01070");
					dwqk01Int = getInteger(tmpDwqk0101);
					sqlTmp= "select * from dwqk01,dwzz01 where   dwqk0101=dwzz0102 and dwzz0102 ='"+dwqk01Int+"' and dwzz0104='招投标'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01070(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01071("招投标代理"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01070(rs.getString("xmqk01070"));
						xmqk01.setXmqk01071(rs.getString("xmqk01071"));
					}
					
					xmqk01.setXmqk01072(rs.getString("xmqk01072"));
					xmqk01.setXmqk01073(rs.getDouble("xmqk01073"));
					xmqk01.setXmqk01074(rs.getString("xmqk01074"));
					xmqk01.setXmqk01075(rs.getString("xmqk01075"));
					xmqk01.setXmqk01076(rs.getString("xmqk01076"));
					xmqk01.setXmqk01077(rs.getString("xmqk01077"));
					xmqk01.setXmqk01078(rs.getString("xmqk01078"));
					///对 监理单位进行单位名称和资质的判别   如果在单位表里面不存在  则使用原始记录
					sqlTmp= "select * from dwqk01,dwzz01 where  dwqk0101=dwzz0102 and dwzz0102 ='"+rs.getString("xmqk01079")+"' and dwzz0104='监理'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01079(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01080("监理"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01079(rs.getString("xmqk01079"));
						xmqk01.setXmqk01080(rs.getString("xmqk01080"));
					}
				
					xmqk01.setXmqk01081(rs.getString("xmqk01081"));
					xmqk01.setXmqk01082(rs.getString("xmqk01082"));
					/// modify by cuiyi 20130501  招投标代理机构及资质     根据id从 单位基本情况和资质表里面去取
					tmpDwqk0101 = rs.getString("xmqk01083")==null?"":rs.getString("xmqk01083");
					dwqk01Int = getInteger(tmpDwqk0101);
					sqlTmp= "select * from dwqk01,dwzz01 where   dwqk0101=dwzz0102 and dwzz0102 ='"+dwqk01Int+"' and dwzz0104='招投标'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01083(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01084("招投标代理"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01083(rs.getString("xmqk01083"));
						xmqk01.setXmqk01084(rs.getString("xmqk01084"));
					}
					xmqk01.setXmqk01085(rs.getString("xmqk01085"));
					xmqk01.setXmqk01086(rs.getDouble("xmqk01086"));
					xmqk01.setXmqk01087(rs.getString("xmqk01087"));
					xmqk01.setXmqk01088(rs.getString("xmqk01088"));
					xmqk01.setXmqk01089(rs.getString("xmqk01089"));
					xmqk01.setXmqk01090(rs.getString("xmqk01090"));
					xmqk01.setXmqk01091(rs.getString("xmqk01091"));
					///对施工单位进行单位名称和资质的判别   如果在单位表里面不存在  则使用原始记录
					sqlTmp= "select * from dwqk01,dwzz01 where  dwqk0101=dwzz0102 and dwzz0102 ='"+rs.getString("xmqk01092")+"' and dwzz0104='施工'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01092(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01093("施工"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01092(rs.getString("xmqk01092"));
						xmqk01.setXmqk01093(rs.getString("xmqk01093"));
					}
					
					xmqk01.setXmqk01094(rs.getString("xmqk01094"));
					xmqk01.setXmqk01095(rs.getString("xmqk01095"));
					/// modify by cuiyi 20130501  招投标代理机构及资质     根据id从 单位基本情况和资质表里面去取
					tmpDwqk0101 = rs.getString("xmqk01096")==null?"":rs.getString("xmqk01096");
					dwqk01Int = getInteger(tmpDwqk0101);
					sqlTmp= "select * from dwqk01,dwzz01 where   dwqk0101=dwzz0102 and dwzz0102 ='"+dwqk01Int+"' and dwzz0104='招投标'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01096(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01097("招投标代理"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01096(rs.getString("xmqk01096"));
						xmqk01.setXmqk01097(rs.getString("xmqk01097"));
					}
					
					xmqk01.setXmqk01098(rs.getString("xmqk01098"));
					xmqk01.setXmqk01099(rs.getDouble("xmqk01099"));
					xmqk01.setXmqk01100(rs.getString("xmqk01100"));
					xmqk01.setXmqk01101(rs.getString("xmqk01101"));
					xmqk01.setXmqk01102(rs.getString("xmqk01102"));
					xmqk01.setXmqk01103(rs.getString("xmqk01103"));
					xmqk01.setXmqk01104(rs.getString("xmqk01104"));
					///对监测单位进行单位名称和资质的判别   如果在单位表里面不存在  则使用原始记录
					sqlTmp= "select * from dwqk01,dwzz01 where  dwqk0101=dwzz0102 and dwzz0102 ='"+rs.getString("xmqk01105")+"' and dwzz0104='监测'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01105(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01106("监测"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01105(rs.getString("xmqk01105"));
						xmqk01.setXmqk01106(rs.getString("xmqk01106"));
					}
					xmqk01.setXmqk01107(rs.getString("xmqk01107"));
					xmqk01.setXmqk01108(rs.getString("xmqk01108"));
					/// modify by cuiyi 20130501  招投标代理机构及资质     根据id从 单位基本情况和资质表里面去取
					tmpDwqk0101 = rs.getString("xmqk01109")==null?"":rs.getString("xmqk01109");
					dwqk01Int = getInteger(tmpDwqk0101);
					sqlTmp= "select * from dwqk01,dwzz01 where   dwqk0101=dwzz0102 and dwzz0102 ='"+dwqk01Int+"' and dwzz0104='招投标'";
					psTmp = conn.prepareStatement(sqlTmp);
					rsTmp=psTmp.executeQuery();
					if(rsTmp.next()){
						xmqk01.setXmqk01109(rsTmp.getString("dwqk0103"));
						xmqk01.setXmqk01110("招投标代理"+rsTmp.getString("dwzz0105"));
					}else{
						xmqk01.setXmqk01109(rs.getString("xmqk01109"));
						xmqk01.setXmqk01110(rs.getString("xmqk01110"));
					}
					
					xmqk01.setXmqk01111(rs.getString("xmqk01111"));
					xmqk01.setXmqk01112(rs.getDouble("xmqk01112"));
					xmqk01.setXmqk01113(rs.getString("xmqk01113"));
					xmqk01.setXmqk01114(rs.getString("xmqk01114"));
					xmqk01.setXmqk01115(rs.getString("xmqk01115"));
					xmqk01.setXmqk01116(rs.getString("xmqk01116"));
					xmqk01.setXmqk01117(rs.getString("xmqk01117"));
					xmqk01.setXmqk01118(rs.getString("xmqk01118")==null?"":rs.getString("xmqk01118"));
					xmqk01.setXmqk01119(rs.getString("xmqk01119")==null?"":rs.getString("xmqk01119"));
					xmqk01.setXmqk01120(rs.getString("xmqk01120"));
					xmqk01.setXmqk01121(rs.getString("xmqk01121")==null?"":rs.getString("xmqk01121"));
					xmqk01.setXmqk01122(rs.getString("xmqk01122"));
					xmqk01.setXmqk01123(rs.getString("xmqk01123"));
					xmqk01.setXmqk01124(rs.getString("xmqk01124"));
					xmqk01.setXmqk01125(rs.getString("xmqk01125"));
					xmqk01.setXmqk01126(rs.getString("xmqk01126"));
					xmqk01.setXmqk01127(rs.getString("xmqk01127"));
					xmqk01.setXmqk01128(rs.getInt("xmqk01128"));
					xmqk01.setXmqk01129(rs.getInt("xmqk01129"));
					xmqk01.setXmqk01130(rs.getInt("xmqk01130"));
					xmqk01.setXmqk01131(rs.getInt("xmqk01131"));
					xmqk01.setXmqk01132(rs.getString("xmqk01132"));
					xmqk01.setXmqk01133(rs.getInt("xmqk01133"));
					xmqk01.setXmqk01134(rs.getInt("xmqk01134"));
					xmqk01.setXmqk01135(rs.getString("xmqk01135"));
					xmqk01.setXmqk01136(rs.getString("xmqk01136"));
					xmqk01.setXmqk01137(rs.getString("xmqk01137"));
					xmqk01List.add(xmqk01);
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return xmqk01List;
	}
	public Boolean DelXmqk(String id) {
/*		Boolean flag =false;
		   conn=JdbcUtil.getConnection();
		   String sql = "";
		   sql = "delete from xmqk01  where xmqk01001=?";
			try {
				ps = conn.prepareStatement(sql);
				ps.setString(1, xmqk01001);
				int number=ps.executeUpdate();
				if(number>0)
				{
					flag=true;
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return flag;*/
		boolean bl=false;
		String sqlXmqk = "delete from xmqk01 where xmqk01001 = "+id;
		String sqlZjpf = "delete from zjpf01 where zjpf0102="+id;
		String sqlCjdw = "delete from cjdw01 where cjdw0102="+id;
		String sqlZhd = "delete from zhd01 where zhd01001="+id;
		if(JdbcUtil.executeSql(sqlXmqk)>0&&JdbcUtil.executeSql(sqlCjdw)>=0&&JdbcUtil.executeSql(sqlZjpf)>=0&&JdbcUtil.executeSql(sqlZhd)>=0){
			bl = true;
		}
		return bl;
	}
	public Boolean UpdateXmqk(Xmqk01 xmqk01) {
		 Boolean flag =false;
		   conn=JdbcUtil.getConnection();
		   String sql = "";
		   sql = "update xmqk01 set  xmqk01002=?,xmqk01003 =?,xmqk01004=?,xmqk01005=?,xmqk01006=?,xmqk01007=?,xmqk01008=?,xmqk01009=?,xmqk01010=?," +
		   		"xmqk01011=?,xmqk01012=?,xmqk01013=?,xmqk01014=?,xmqk01015=?,xmqk01016=?,xmqk01017=?,xmqk01018 =?,xmqk01019=?,xmqk01020=?," +
		   		"xmqk01021=?,xmqk01022=?,xmqk01023=?,xmqk01024=?,xmqk01025=?,xmqk01026=?,xmqk01027=?,xmqk01028=?,xmqk01029=?,xmqk01030=?," +
		   		"xmqk01031=?,xmqk01032=?,xmqk01033=?,xmqk01034=?,xmqk01035=?,xmqk01036=?,xmqk01037=?,xmqk01038=?,xmqk01039=?,xmqk01040 =?," +
		   		"xmqk01041=?,xmqk01042=?,xmqk01043=?,xmqk01044=?,xmqk01045=?,xmqk01046=?,xmqk01047=?,xmqk01048=?,xmqk01049=?,xmqk01050=?," +
		   		"xmqk01051=?,xmqk01052=?,xmqk01053=?,xmqk01054=?,xmqk01055=?,xmqk01056=?,xmqk01057=?,xmqk01058=?,xmqk01059=?,xmqk01060 =?," +
		   		"xmqk01061=?,xmqk01062=?,xmqk01063=?,xmqk01064=?,xmqk01065=?,xmqk01066=?,xmqk01067=?,xmqk01068=?,xmqk01069=?,xmqk01070=?," +
		   		"xmqk01071=?,xmqk01072=?,xmqk01073=?,xmqk01074=?,xmqk01075=?,xmqk01076=?,xmqk01077=?,xmqk01078=?,xmqk01079=?,xmqk01080 =?, " +
		   		"xmqk01081 =?,xmqk01082=?,xmqk01083=?,xmqk01084=?,xmqk01085=?,xmqk01086=?,xmqk01087=?,xmqk01088=?,xmqk01089=?,xmqk01090=?," +
		   		"xmqk01091=?,xmqk01092=?,xmqk01093=?,xmqk01094=?,xmqk01095=?,xmqk01096=?,xmqk01097=?,xmqk01098 =?,xmqk01099=?,xmqk01100=?," +
		   		"xmqk01101=?,xmqk01102=?,xmqk01103=?,xmqk01104=?,xmqk01105=?,xmqk01106=?,xmqk01107=?,xmqk01108=?,xmqk01109=?,xmqk01110=?," +
		   		"xmqk01111=?,xmqk01112=?,xmqk01113=?,xmqk01114=?,xmqk01115=?,xmqk01116=?,xmqk01117=?,xmqk01118 =?,xmqk01119=?,xmqk01120=?," +
		   		"xmqk01121=?,xmqk01122=?,xmqk01123=?,xmqk01124=?,xmqk01125=?,xmqk01126=?,xmqk01127=?,xmqk01128=?,xmqk01129=?,xmqk01130=?," +
		   		"xmqk01131=?,xmqk01132=?,xmqk01133=?,xmqk01134=?,xmqk01135 =?,xmqk01136=?,xmqk01137=?  where xmqk01001=?";
			try {
				ps = conn.prepareStatement(sql);
				ps.setString(1, xmqk01.getXmqk01002());
				ps.setString(2, xmqk01.getXmqk01003());
				ps.setString(3, xmqk01.getXmqk01004());
				ps.setString(4, xmqk01.getXmqk01005());
				ps.setString(5, xmqk01.getXmqk01006());
				ps.setString(6, xmqk01.getXmqk01007());
				ps.setString(7, xmqk01.getXmqk01008());
				ps.setString(8, xmqk01.getXmqk01009());
				ps.setString(9, xmqk01.getXmqk01010());
				ps.setString(10, xmqk01.getXmqk01011());
				ps.setString(11,xmqk01.getXmqk01012());
				ps.setString(12,xmqk01.getXmqk01013());
				ps.setString(13,xmqk01.getXmqk01014());
				ps.setString(14,xmqk01.getXmqk01015());
				ps.setString(15,xmqk01.getXmqk01016());
				ps.setDouble(16,xmqk01.getXmqk01017());
				ps.setDouble(17,xmqk01.getXmqk01018());
				ps.setDouble(18,xmqk01.getXmqk01019());
				ps.setDouble(19,xmqk01.getXmqk01020());
				ps.setDouble(20,xmqk01.getXmqk01021());
				ps.setDouble(21,xmqk01.getXmqk01022());
				ps.setDouble(22,xmqk01.getXmqk01023());
				ps.setDouble(23,xmqk01.getXmqk01024());
				ps.setString(24,xmqk01.getXmqk01025());
				ps.setString(25,xmqk01.getXmqk01026());
				ps.setString(26,xmqk01.getXmqk01027());
				ps.setString(27,xmqk01.getXmqk01028());
				ps.setString(28,xmqk01.getXmqk01029());
				ps.setString(29,xmqk01.getXmqk01030());
				ps.setString(30,xmqk01.getXmqk01031());
				ps.setString(31,xmqk01.getXmqk01032());
				ps.setString(32,xmqk01.getXmqk01033());
				ps.setString(33,xmqk01.getXmqk01034());
				ps.setString(34,xmqk01.getXmqk01035());
				ps.setString(35,xmqk01.getXmqk01036());
				ps.setDouble(36,xmqk01.getXmqk01037());
				ps.setString(37,xmqk01.getXmqk01038());
				ps.setString(38,xmqk01.getXmqk01039());
				ps.setString(39,xmqk01.getXmqk01040());
				ps.setString(40,xmqk01.getXmqk01041());
				ps.setString(41,xmqk01.getXmqk01042());
				ps.setDouble(42,xmqk01.getXmqk01043());
				ps.setDouble(43,xmqk01.getXmqk01044());
				ps.setDouble(44,xmqk01.getXmqk01045());
				ps.setDouble(45,xmqk01.getXmqk01046());
				ps.setDouble(46,xmqk01.getXmqk01047());
				ps.setString(47,xmqk01.getXmqk01048());
				ps.setString(48,xmqk01.getXmqk01049());
				ps.setString(49,xmqk01.getXmqk01050());
				ps.setString(50,xmqk01.getXmqk01051());
				ps.setString(51,xmqk01.getXmqk01052());
				ps.setString(52,xmqk01.getXmqk01053());
				ps.setString(53,xmqk01.getXmqk01054());
				ps.setString(54,xmqk01.getXmqk01055());
				ps.setString(55,xmqk01.getXmqk01056());
				ps.setString(56,xmqk01.getXmqk01057());
				ps.setString(57,xmqk01.getXmqk01058());
				ps.setString(58,xmqk01.getXmqk01059());
				ps.setDouble(59,xmqk01.getXmqk01060());
				ps.setString(60,xmqk01.getXmqk01061());
				ps.setString(61,xmqk01.getXmqk01062());
				ps.setString(62,xmqk01.getXmqk01063());
				ps.setString(63,xmqk01.getXmqk01064());
				ps.setString(64,xmqk01.getXmqk01065());
				ps.setString(65,xmqk01.getXmqk01066());
				ps.setString(66,xmqk01.getXmqk01067());
				ps.setString(67,xmqk01.getXmqk01068());
				ps.setString(68,xmqk01.getXmqk01069());
				ps.setString(69,xmqk01.getXmqk01070());
				ps.setString(70,xmqk01.getXmqk01071());
				ps.setString(71,xmqk01.getXmqk01072());
				ps.setDouble(72,xmqk01.getXmqk01073());
				ps.setString(73,xmqk01.getXmqk01074());
				ps.setString(74,xmqk01.getXmqk01075());
				ps.setString(75,xmqk01.getXmqk01076());
				ps.setString(76,xmqk01.getXmqk01077());
				ps.setString(77,xmqk01.getXmqk01078());
				ps.setString(78,xmqk01.getXmqk01079());
				ps.setString(79,xmqk01.getXmqk01080());
				
				ps.setString(80,xmqk01.getXmqk01081());
				ps.setString(81,xmqk01.getXmqk01082());
				ps.setString(82,xmqk01.getXmqk01083());
				ps.setString(83,xmqk01.getXmqk01084());
				ps.setString(84,xmqk01.getXmqk01085());
				ps.setDouble(85,xmqk01.getXmqk01086());
				ps.setString(86,xmqk01.getXmqk01087());
				ps.setString(87,xmqk01.getXmqk01088());
				ps.setString(88,xmqk01.getXmqk01089());
				ps.setString(89,xmqk01.getXmqk01090());
				ps.setString(90,xmqk01.getXmqk01091());
				ps.setString(91,xmqk01.getXmqk01092());
				ps.setString(92,xmqk01.getXmqk01093());
				ps.setString(93,xmqk01.getXmqk01094());
				ps.setString(94,xmqk01.getXmqk01095());
				ps.setString(95,xmqk01.getXmqk01096());
				ps.setString(96,xmqk01.getXmqk01097());
				ps.setString(97,xmqk01.getXmqk01098());
				ps.setDouble(98,xmqk01.getXmqk01099());
				ps.setString(99,xmqk01.getXmqk01100());
				ps.setString(100,xmqk01.getXmqk01101());
				ps.setString(101,xmqk01.getXmqk01102());
				ps.setString(102,xmqk01.getXmqk01103());
				ps.setString(103,xmqk01.getXmqk01104());
				ps.setString(104,xmqk01.getXmqk01105());
				ps.setString(105,xmqk01.getXmqk01106());
				ps.setString(106,xmqk01.getXmqk01107());
				ps.setString(107,xmqk01.getXmqk01108());
				ps.setString(108,xmqk01.getXmqk01109());
				ps.setString(109,xmqk01.getXmqk01110());
				ps.setString(110,xmqk01.getXmqk01111());
				ps.setDouble(111,xmqk01.getXmqk01112());
				ps.setString(112,xmqk01.getXmqk01113());
				ps.setString(113,xmqk01.getXmqk01114());
				ps.setString(114,xmqk01.getXmqk01115());
				ps.setString(115,xmqk01.getXmqk01116());
				ps.setString(116,xmqk01.getXmqk01117());
				ps.setString(117,xmqk01.getXmqk01118());
				ps.setString(118,xmqk01.getXmqk01119());
				ps.setString(119,xmqk01.getXmqk01120());
				ps.setString(120,xmqk01.getXmqk01121());
				ps.setString(121,xmqk01.getXmqk01122());
				ps.setString(122,xmqk01.getXmqk01123());
				ps.setString(123,xmqk01.getXmqk01124());
				ps.setString(124,xmqk01.getXmqk01125());
				ps.setString(125, xmqk01.getXmqk01126());
				ps.setString(126, xmqk01.getXmqk01127());
				ps.setInt(127, xmqk01.getXmqk01128());
				ps.setInt(128, xmqk01.getXmqk01129());
				ps.setInt(129, xmqk01.getXmqk01130());
				ps.setInt(130, xmqk01.getXmqk01131());
				ps.setString(131,xmqk01.getXmqk01132());
				ps.setInt(132, xmqk01.getXmqk01133());
				ps.setInt(133, xmqk01.getXmqk01134());
				ps.setString(134,xmqk01.getXmqk01135());
				ps.setString(135,xmqk01.getXmqk01136());
				ps.setString(136,xmqk01.getXmqk01137());
				ps.setInt(137, xmqk01.getXmqk01001());
				int number=ps.executeUpdate();
				if(number>0)
				{
					flag=true;
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return flag;
	}
	public Boolean checkXmqkInfo(String xmName) {
		Boolean flag =false;
		conn=JdbcUtil.getConnection();
		String sql = "";
		sql = "select * from xmqk01 where xmqk01003 =?";
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, xmName);
			ResultSet rs = ps.executeQuery();
			flag = rs.next();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally
		{
			JdbcUtil.closeAll(ps,conn);
		}
		return flag;
	}
	public Boolean checkXmqkInfoExceptId(String xmName, int xmId) {
		Boolean flag =false;
		conn=JdbcUtil.getConnection();
		String sql = "";
		sql = "select * from xmqk01 where xmqk01003 =? and xmqk01001 !="+xmId;
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, xmName);
			ResultSet rs = ps.executeQuery();
			flag = rs.next();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally
		{
			JdbcUtil.closeAll(ps,conn);
		}
		return flag;
	}
	
	private int getInteger(String value){
		try {
			return Integer.parseInt(value);
		} catch (NumberFormatException e) {
			return 0;
		}
	}
	/* 2013-5-8下午06:23:53
	 * auther:cuiyi 
	 * 
	 */
	/*public List<Xmfj01> SearchXmfj(String xmName,String  fjName,String wdType,String wdsubType){
		List<Xmfj01> xmfj01List=new ArrayList<Xmfj01>();
		conn=JdbcUtil.getConnection();
		String sql = "select XMQK01001,XMQK01002,XMQK01003,XMQK01025,XMQK01026,XMQK01027,XMQK01028,XMQK01029," +
				"XMQK01038,XMQK01039,XMQK01042,"+//勘察
				"XMQK01061,XMQK01062,XMQK01065,"+//可研
				"XMQK01074,XMQK01075,XMQK01078,"+//设计
				"XMQK01087,XMQK01088,XMQK01091,"+//监理
				"XMQK01100,XMQK01101,XMQK01104,"+//施工
				"XMQK01113,XMQK01114,XMQK01117,"+//监测
				"XMQK01122,XMQK01123,XMQK01126,XMQK01127" +//竣工
				" from xmqk01 where xmqk01003 like '%"+xmName+"%'";
		try{
			conn=JdbcUtil.getConnection();
			ps = conn.prepareStatement(sql);
			rs=ps.executeQuery();
			while(rs.next()){
				int xmqk01001 = rs.getInt("XMQK01001");
				String xmqk01002 = rs.getString("XMQK01002");
				String xmqk01003 = rs.getString("XMQK01003");
				String xmqk01025 = rs.getString("XMQK01025");
				String xmqk01026 = rs.getString("XMQK01026");
				String xmqk01027 = rs.getString("XMQK01027");
				String xmqk01028 = rs.getString("XMQK01028");
				String xmqk01029 = rs.getString("XMQK01029");
				String xmqk01038 = rs.getString("XMQK01038");
				String xmqk01039 = rs.getString("XMQK01039");
				String xmqk01042 = rs.getString("XMQK01042");
				String xmqk01061 = rs.getString("XMQK01061");
				String xmqk01062 = rs.getString("XMQK01062");
				String xmqk01065 = rs.getString("XMQK01065");
				String xmqk01074 = rs.getString("XMQK01074");
				String xmqk01075 = rs.getString("XMQK01075");
				String xmqk01078 = rs.getString("XMQK01078");
				String xmqk01087 = rs.getString("XMQK01087");
				String xmqk01088 = rs.getString("XMQK01088");
				String xmqk01091 = rs.getString("XMQK01091");
				String xmqk01100 = rs.getString("XMQK01100");
				String xmqk01101 = rs.getString("XMQK01101");
				String xmqk01104 = rs.getString("XMQK01104");
				String xmqk01113 = rs.getString("XMQK01113");
				String xmqk01114 = rs.getString("XMQK01114");
				String xmqk01117 = rs.getString("XMQK01117");
				String xmqk01122 = rs.getString("XMQK01122");
				String xmqk01123 = rs.getString("XMQK01123");
				String xmqk01126 = rs.getString("XMQK01126");
				String xmqk01127 = rs.getString("XMQK01127");
				if(wdType.equals("0")){
					//批文   PW
					//xmqk01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "PW", "00", xmqk01025, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "PW", "PW01", xmqk01025, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "PW", "PW02", xmqk01026, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "PW", "PW03", xmqk01027, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "PW", "PW04", xmqk01028, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "PW", "PW05", xmqk01029, fjName));
					//勘察  KC
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "KC", "KC00", xmqk01042, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "KC", "KC01", xmqk01039, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "KC", "KC02", xmqk01038, fjName));
					//可研  KY
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "KY", "KY00", xmqk01065, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "KY", "KY01", xmqk01062, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "KY", "KY02", xmqk01061, fjName));
					//设计  SJ
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "SJ", "SJ00", xmqk01078, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "SJ", "SJ01", xmqk01075, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "SJ", "SJ02", xmqk01074, fjName));
					//施工  SG
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "SG", "SG00", xmqk01104, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "SG", "SG01", xmqk01101, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "SG", "SG02", xmqk01100, fjName));
					
					//监理  JL
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JL", "JL00", xmqk01091, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JL", "JL01", xmqk01088, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JL", "JL02", xmqk01087, fjName));
					
					//监测  JC
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JC", "JC00", xmqk01117, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JC", "JC01", xmqk01114, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JC", "JC02", xmqk01113, fjName));
					
					//竣工  JG
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JG", "JG00", xmqk01126, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JG", "JG01", xmqk01123, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JG", "JG02", xmqk01122, fjName));
					xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, "JG", "JG03", xmqk01127, fjName));
					
				}else{
					switch(wdfjTypeEnum.valueOf(wdType)){
					case PW://批文   PW
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"01", xmqk01025, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"02", xmqk01026, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"03", xmqk01027, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"04", xmqk01028, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"05", xmqk01029, fjName));
						break;
					case KY://可研  KY
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"00", xmqk01065, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"01", xmqk01062, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"02", xmqk01061, fjName));
						break;
					case KC://勘察  KC
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"00", xmqk01042, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"01", xmqk01039, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"02", xmqk01038, fjName));
						break;
					case SJ://设计  SJ
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"00", xmqk01078, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"01", xmqk01075, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"02", xmqk01074, fjName));
						break;
					case SG://施工  SG
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"00", xmqk01104, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"01", xmqk01101, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"02", xmqk01100, fjName));
						break;
					case JL://监理  JL
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"00", xmqk01091, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"01", xmqk01088, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"02", xmqk01087, fjName));
						break;
					case JC://监测  JC
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"00", xmqk01117, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"01", xmqk01114, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"02", xmqk01113, fjName));
						break;
					case JG://竣工  JG
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"00", xmqk01126, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"01", xmqk01123, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"02", xmqk01122, fjName));
						xmfj01List.add(getXmfjObj(xmqk01001, xmqk01002, xmqk01003, wdType, wdType+"03", xmqk01127, fjName));
						break;	
					}
				}
			}
		}catch (Exception e) {
			System.out.println("查询项目附件出错");
		}
		return xmfj01List;
	}*/
	private Xmfj01 getXmfjObj(int xmId,String xmCode,String xmName,String fjType,String fjSubType,String fjUrl,String fjName){
		Xmfj01 xmfj = new Xmfj01();
		if((fjUrl!=null&&fjUrl.indexOf(fjName)>-1)||(fjUrl==null&&fjName.equals(""))){
			xmfj.setXmfj0101(xmId);
			xmfj.setXmfj0102(xmCode);
			xmfj.setXmfj0103(xmName);
			xmfj.setXmfj0104(fjType);
			xmfj.setXmfj0105(fjSubType);
			xmfj.setXmfj0106(fjUrl);
		}
		return xmfj;
	}
	
	public Boolean updateXmfj(String xmfj0101, String xmfj0106, String type) {
		Boolean flag =false;
		   conn=JdbcUtil.getConnection();
		   String sql = "";
		   String column = getColumnByType(type);
		   String[] tableName = getTableByType(type);
		   sql = "update "+tableName[0]+" set " +column+"=?"+
		   		" where "+tableName[1]+"=?";
			try {
				ps = conn.prepareStatement(sql);
				ps.setString(1, xmfj0106);
				ps.setString(2, xmfj0101);
				int number=ps.executeUpdate();
				if(number>0)
				{
					flag=true;
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return flag;
	} 
	 private String getColumnByType(String type){
		 	String column = "";
			switch(wdfjTypeColunmEnum.valueOf(type)){
			////////////////////////
			case PW01:
				column = "zjpf0106";
				break;
			case PW02:
				column = "zjpf0106";
				break;
			case PW03:
				column = "zjpf0106";
				break;
			case PW04:
				column = "zjpf0106";
				break;
			case PW05:
				column = "zjpf0106";
				break;
			////////////////////////
			case KY00:
				column = "cjdw0111";
				break;
			case KY01:
				column = "cjdw0112";
				break;
			case KY02:
				column = "cjdw0113";
				break;
			////////////////////////
			case KC00:
				column = "cjdw0111";
				break;
			case KC01:
				column = "cjdw0112";
				break;
			case KC02:
				column = "cjdw0113";
				break;
////////////////////////
			case SJ00:
				column = "cjdw0111";
				break;
			case SJ01:
				column = "cjdw0112";
				break;
			case SJ02:
				column = "cjdw0113";
				break;
////////////////////////
			case SG00:
				column = "cjdw0111";
				break;
			case SG01:
				column = "cjdw0112";
				break;
			case SG02:
				column = "cjdw0113";
				break;
////////////////////////
			case JL00:
				column = "cjdw0111";
				break;
			case JL01:
				column = "cjdw0112";
				break;
			case JL02:
				column = "cjdw0113";
				break;
////////////////////////
			case JC00:
				column = "cjdw0111";
				break;
			case JC01:
				column = "cjdw0112";
				break;
			case JC02:
				column = "cjdw0113";
				break;
////////////////////////
			case JG00:
				column = "xmqk01126";
				break;
			case JG01:
				column = "xmqk01123";
				break;
			case JG02:
				column = "xmqk01122";
				break;
			case JG03:
				column = "xmqk01127";
				break;
			}
			return column;
	 }
	 private String[] getTableByType(String type){
		 String[] tableName = new String[]{"xmqk01","xmqk01001"};
		 if(type.indexOf("PW")>-1){
			 tableName[0] = "zjpf01";
			 tableName[1] = "zjpf0101";
		 }else if(type.indexOf("JG")>-1){
			 tableName[0] = "xmqk01";
			 tableName[1] = "xmqk01001";
		 }else {
			 tableName[0] = "cjdw01";
			 tableName[1] = "cjdw0101";
		 }
		 return tableName;
	 }
	 public enum wdfjTypeEnum {  
		 PW,KY,KC,SJ,SG,JL,JC,JG;
	 }
	 public enum wdfjTypeColunmEnum {  
		 PW01,PW02,PW03,PW04,PW05,
		 KY01,KY02,KY00,
		 KC01,KC02,KC00,
		 SJ01,SJ02,SJ00,
		 SG01,SG02,SG00,
		 JL01,JL02,JL00,
		 JC01,JC02,JC00,
		 JG01,JG02,JG03,JG00;
   }
	 /**
	 * 2013-5-28
	 * 崔艺
	 * @param xmqk
	 * @param cjdwList
	 * @param zjpfList
	 * @return   0:项目录入失败  1资金批复录入失败  2参建单位录入失败
	 */
	public Boolean AddXmqk(Xmqk01New xmqk01,List<Zjpf01> zjpfList,List<Cjdw01> cjdwList,List<ZHD01> zhdList){
		//String log = "";
		 conn=JdbcUtil.getConnection();
		 Calendar cal = Calendar.getInstance();
		 String sql = "";
		 int year = cal.get(Calendar.YEAR);
		 String tmpYear = xmqk01.getXMQK01005()==null||xmqk01.getXMQK01005().equals("")||xmqk01.getXMQK01005().equals("请选择")?String.valueOf(year):xmqk01.getXMQK01005();
		 sql = "select  xmqk01002 from XMQK01 where XMQK01002 like 'XM"+tmpYear+"____' order by XMQK01002 desc ";
		 String xmqk01002 = "";
		 
			try {
				ps = conn.prepareStatement(sql);
				ResultSet rs = ps.executeQuery();
				if(rs.next()){
					String maxCode = rs.getString("xmqk01002");
					int tmpCode =Integer.parseInt(maxCode.substring(6))+1;
					xmqk01002 = maxCode.substring(0, 6)+commUtils.completStr(String.valueOf(tmpCode), 4);
				}else{
					xmqk01002 = "XM"+tmpYear+"0001";
				}
				 sql = "insert into xmqk01  values(oa_seq.nextval,?,?,?,?,?,?,?,?,?,?," +
			  		"?,?,?,?,?,?,?,?,?,?," +
			  		"?,?,?,?,?,?,?,?,?,?," +
			  		"?,?,?,?,?,?,?,?,?,?," +
			  		"?)";
				ps = conn.prepareStatement(sql);
				ps.setString(1, xmqk01002);
				ps.setString(2, xmqk01.getXMQK01003());
				ps.setString(3, xmqk01.getXMQK01004());
				ps.setString(4, xmqk01.getXMQK01005());
				ps.setString(5, xmqk01.getXMQK01006());
				ps.setString(6, xmqk01.getXMQK01007());
				ps.setString(7, xmqk01.getXMQK01008());//输入
				ps.setString(8, xmqk01.getXMQK01009());//输入
				ps.setString(9, xmqk01.getXMQK01010());
				ps.setString(10, xmqk01.getXMQK01011());
				ps.setString(11,xmqk01.getXMQK01012());
				ps.setString(12,xmqk01.getXMQK01013());
				ps.setString(13,xmqk01.getXMQK01014());
				ps.setString(14,xmqk01.getXMQK01015());
				ps.setString(15,xmqk01.getXMQK01016());
				ps.setDouble(16,xmqk01.getXMQK01017()==null?Double.valueOf("0"):xmqk01.getXMQK01017());
				ps.setDouble(17,xmqk01.getXMQK01018()==null?Double.valueOf("0"):xmqk01.getXMQK01018());
				ps.setDouble(18,xmqk01.getXMQK01019()==null?Double.valueOf("0"):xmqk01.getXMQK01019());
				
				ps.setString(19,xmqk01.getXMQK01118());
				ps.setString(20,xmqk01.getXMQK01119());
				ps.setString(21,xmqk01.getXMQK01120());
				ps.setString(22,xmqk01.getXMQK01121());
				ps.setString(23,xmqk01.getXMQK01122());
				ps.setString(24,xmqk01.getXMQK01123());
				ps.setString(25,xmqk01.getXMQK01124());
				ps.setString(26,xmqk01.getXMQK01125());
				ps.setString(27,xmqk01.getXMQK01126());
				ps.setString(28,xmqk01.getXMQK01127());
				
				ps.setInt(29, xmqk01.getXMQK01128()==null?0:xmqk01.getXMQK01128());
				ps.setInt(30, xmqk01.getXMQK01129()==null?0:xmqk01.getXMQK01129());
				ps.setInt(31, xmqk01.getXMQK01130()==null?0:xmqk01.getXMQK01130());
				ps.setInt(32, xmqk01.getXMQK01131()==null?0:xmqk01.getXMQK01131());
				ps.setString(33,xmqk01.getXMQK01132());
				ps.setDouble(34, xmqk01.getXMQK01133()==null?Double.valueOf("0"):xmqk01.getXMQK01133());
				ps.setDouble(35, xmqk01.getXMQK01134()==null?Double.valueOf("0"):xmqk01.getXMQK01134());
				ps.setString(36,xmqk01.getXMQK01135());
				ps.setString(37,xmqk01.getXMQK01136());
				ps.setString(38,xmqk01.getXMQK01137());
				ps.setString(39,xmqk01.getXMQK01138());
				ps.setDouble(40,xmqk01.getXMQK01139()==null?Double.valueOf("0"):xmqk01.getXMQK01139());
				ps.setDouble(41,xmqk01.getXMQK01140()==null?Double.valueOf("0"):xmqk01.getXMQK01140());
				int number=ps.executeUpdate();
				if(number>0)///项目录入成功
				{
					sql = "select xmqk01001 from xmqk01 where xmqk01003='"+xmqk01.getXMQK01003()+"' order by xmqk01001 desc";
					ps = conn.prepareStatement(sql);
					rs=ps.executeQuery();
					int xmId = 0;
					if(rs.next())
						xmId = rs.getInt(1);
					if(xmId==0){
						System.out.println("项目录入失败");
						return false;
					}
						
					//////资金批复录入
					for(int i =0;zjpfList!=null&&i<zjpfList.size();i++){
						Zjpf01 zjpf = (Zjpf01)zjpfList.get(i);
						sql = "insert into zjpf01 values(oa_seq.nextval,?,?,?,?,?,?)";
						ps = conn.prepareStatement(sql);
						ps.setInt(1, xmId);
						ps.setString(2, zjpf.getZJPF0103());
						ps.setString(3, zjpf.getZJPF0104());
						ps.setDouble(4, zjpf.getZJPF0105());
						ps.setString(5, zjpf.getZJPF0106());
						ps.setString(6, zjpf.getZJPF0107());
						number=ps.executeUpdate();
						if(!(number>0)){//资金批复插入失败。数据库回滚，删除之前所有数据。
							JdbcUtil.executeSql("delete from xmqk01 where xmqk01001="+xmId);
							JdbcUtil.executeSql("delete from zjpf01 where zjpf0102="+xmId);
							System.out.println("资金批复录入失败");
							return false;
						}
					}
					///参建单位录入
					for(int i=0;cjdwList!=null&&i<cjdwList.size();i++){
						
						Cjdw01 cjdw = (Cjdw01)cjdwList.get(i);
						if(cjdw.getCJDW0104().equals("B")||cjdw.getCJDW0104().equals("F")){///可研或者监测输入单位名称为空时，忽略掉此记录
							if(cjdw.getCJDW0116()==null||cjdw.getCJDW0116().equals("")){
								continue;
							}
						}else if(cjdw.getCJDW0103()==0){///单位名称未选择时，忽略掉此记录
							continue;
						}
						sql = "insert into cjdw01 values(oa_seq.nextval,?,?,?,?,?," +
								"?,?,?,?,?," +
								"?,?,?,?,?," +
								"?,?)";
						ps = conn.prepareStatement(sql);
						ps.setInt(1, xmId);
						ps.setInt(2, cjdw.getCJDW0103());
						ps.setString(3, commUtils.parseForCjdwType(cjdw.getCJDW0104()));
						ps.setString(4, cjdw.getCJDW0105());
						ps.setString(5, cjdw.getCJDW0106());
						ps.setString(6, cjdw.getCJDW0107());
						ps.setDouble(7, cjdw.getCJDW0108());
						ps.setString(8, cjdw.getCJDW0109());
						ps.setString(9, cjdw.getCJDW0110());
						ps.setString(10, cjdw.getCJDW0111());
						ps.setString(11, cjdw.getCJDW0112());
						ps.setString(12, cjdw.getCJDW0113());
						ps.setString(13, cjdw.getCJDW0114());
						ps.setString(14, cjdw.getCJDW0115());
						ps.setString(15, cjdw.getCJDW0116());
						ps.setString(16, cjdw.getCJDW0117());
						ps.setString(17, cjdw.getCJDW0118());
						number=ps.executeUpdate();
						if(!(number>0)){//参建单位插入失败。数据库回滚，删除之前所有数据。
							JdbcUtil.executeSql("delete from xmqk01 where xmqk01001="+xmId);
							JdbcUtil.executeSql("delete from zjpf01 where zjpf0102="+xmId);
							JdbcUtil.executeSql("delete from cjdw01 where cjdw0102="+xmId);
							System.out.println("参建单位录入失败");
							return false;
						}
					}
					/////////更新项目总费用字段
					sql = "update xmqk01 set xmqk01019=(select sum(zjpf0105) from zjpf01 where zjpf0102="+xmId+") where xmqk01001 ="+xmId;
					ps = conn.prepareStatement(sql);
					number = ps.executeUpdate();
					///////涉及灾害点录入
					for(int i =0;zhdList!=null&&i<zhdList.size();i++){
						ZHD01 zhd = (ZHD01)zhdList.get(i);
						sql = "insert into zhd01 values(oa_seq.nextval,?,?,?)";
						ps = conn.prepareStatement(sql);
						ps.setInt(1, xmId);
						ps.setString(2, zhd.getZHD01003());
						ps.setString(3, zhd.getZHD01004());
						number=ps.executeUpdate();
						if(!(number>0)){//资金批复插入失败。数据库回滚，删除之前所有数据。
							JdbcUtil.executeSql("delete from xmqk01 where xmqk01001="+xmId);
							JdbcUtil.executeSql("delete from zjpf01 where zjpf0102="+xmId);
							JdbcUtil.executeSql("delete from cjdw01 where cjdw0102="+xmId);
							System.out.println("涉及灾害点录入失败");
							return false;
						}
					}
				}else{///项目录入失败
					System.out.println( "项目录入失败");
					return false;
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
				System.out.println( "项目录入失败");
				return false;
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return true;
	 }
	public String SearchXmqk01(xmqkQueryObj xmqk) {///20131126 modefy
		StringWriter xmlout = new StringWriter();
		conn = JdbcUtil.getConnection();
		StringBuffer sql = new StringBuffer();
		//"select distinct xmqk01001, xmqk01002,xmqk01003,xmqk01005,xmqk01006,xmqk01009,xmqk01016,xmqk01019,xmqk01119,xmqk01136,xmqk01137 from xmqk01,zjpf01,cjdw01,dwqk01 where " +
		//"xmqk01001=zjpf0102 and xmqk01001=cjdw0102 and  cjdw0103=dwqk0101
		String sqlStr = "select distinct xmqk01001, xmqk01002,xmqk01003,xmqk01005,xmqk01006,xmqk01009,xmqk01016,xmqk01019,xmqk01119,xmqk01136,xmqk01137 from xmqk01 where " +
				" 1=1 ";
		if(!xmqk.getCjdw().equals("")&&!xmqk.getZjly().equals("")){
			sqlStr = "select distinct xmqk01001, xmqk01002,xmqk01003,xmqk01005,xmqk01006,xmqk01009,xmqk01016,xmqk01019,xmqk01119,xmqk01136,xmqk01137 from xmqk01,zjpf01,cjdw01,dwqk01 where " +
			" ((xmqk01001=cjdw0102   and  cjdw0103=dwqk0101 and dwqk0103 like '%"+xmqk.getCjdw()+"%') or ( xmqk01001=cjdw0102 and cjdw0117 like '%"+xmqk.getCjdw()+"%' ))"+
			" and xmqk01001=zjpf0102 and zjpf0103 ='"+commUtils.parseForZjpfCodeByName(xmqk.getZjly())+"'";
			if(!xmqk.getZjpfnd().equals("")){//资金批复年度
				sqlStr +=" and zjpf0104='"+xmqk.getZjpfnd()+"'";
				if(!xmqk.getZjpfMin().equals("")){//资金批复金额最小
					sqlStr +=" and zjpf0105>'"+xmqk.getZjpfMin()+"'";
				}
				if(!xmqk.getZjpfMax().equals("")){//资金批复金额最大
					sqlStr +=" and zjpf0105<'"+xmqk.getZjpfMax()+"'";
				}
			}
		}else if(!xmqk.getCjdw().equals("")){//参建单位
				sqlStr = "select distinct xmqk01001, xmqk01002,xmqk01003,xmqk01005,xmqk01006,xmqk01009,xmqk01016,xmqk01019,xmqk01119,xmqk01136,xmqk01137 from xmqk01,cjdw01,dwqk01 where " +
						"( xmqk01001=cjdw0102 and  cjdw0103=dwqk0101 and dwqk0103 like '%"+xmqk.getCjdw()+"%') or (xmqk01001=cjdw0102 and cjdw0117 like '%"+xmqk.getCjdw()+"%') ";
		}else if(!xmqk.getZjly().equals("")){//资金批复类别
			sqlStr = "select distinct xmqk01001, xmqk01002,xmqk01003,xmqk01005,xmqk01006,xmqk01009,xmqk01016,xmqk01019,xmqk01119,xmqk01136,xmqk01137 from xmqk01,zjpf01 where " +
						"xmqk01001=zjpf0102 ";
			sqlStr +=" and zjpf0103 ='"+commUtils.parseForZjpfCodeByName(xmqk.getZjly())+"'";
			if(!xmqk.getZjpfnd().equals("")){//资金批复年度
				sqlStr +=" and zjpf0104='"+xmqk.getZjpfnd()+"'";
				if(!xmqk.getZjpfMin().equals("")){//资金批复金额最小
					sqlStr +=" and zjpf0105>'"+xmqk.getZjpfMin()+"'";
				}
				if(!xmqk.getZjpfMax().equals("")){//资金批复金额最大
					sqlStr +=" and zjpf0105<'"+xmqk.getZjpfMax()+"'";
				}
			}
		}
		
		sql.append(sqlStr);
		if(!xmqk.getXmqk01002().equals("")){//项目统一编号
			sql.append(" and xmqk01002 like '%" + xmqk.getXmqk01002() + "%'");
		}
		if (!xmqk.getXmqk01003().equals("")) {//项目名称
			sql.append(" and xmqk01003 like '%" + xmqk.getXmqk01003() + "%'");
		}
		if (!xmqk.getXmqk01005().equals("")) {//项目年度
			sql.append(" and xmqk01005 ='" + xmqk.getXmqk01005() + "'");
		}
		if (!xmqk.getXmqk01006().equals("")) {//项目类型和子类型
			sql.append(" and xmqk01006 ='" + xmqk.getXmqk01006() + "'");
		}
		///modefy by cuiyi 20130914 项目承担单位直接输入 不从单位表中获取
		if (!xmqk.getXmqk01009().equals("")) {//项目承担单位
			sql.append(" and xmqk01006 like '%" + xmqk.getXmqk01009() + "%'");
		}
		if (!xmqk.getMinfy().equals("")) {//项目总费用
			sql.append(" and xmqk01019>'" + xmqk.getMinfy() + "'");
		}
		if(!xmqk.getMaxfy().equals("")){//项目总费用
			sql.append("and xmqk01019<'" + xmqk.getMaxfy()+ "'");
		} 
		if (!xmqk.getMinjgtime().equals("")) {//竣工时间
			sql.append(" and xmqk01119>'" + xmqk.getMinjgtime() + "'");
		}
		if(!xmqk.getMaxjgtime().equals("")){//竣工时间
			sql.append(" and xmqk01119<'"+ xmqk.getMaxjgtime() + "'");
		}
		if(!xmqk.getXmqk01016().equals("")){//涉及灾害点
			sql.append(" and xmqk01016 like '%"+xmqk.getXmqk01016()+"%'");
		}
		if(!xmqk.getXmqk01136().equals("")){//项目所在市
			sql.append(" and xmqk01136 ='"+xmqk.getXmqk01136()+"'");
		}
		if(!xmqk.getXmqk01137().equals("")){//项目所在县
			sql.append(" and xmqk01137 ='"+xmqk.getXmqk01137()+"'");
		}
		
		if(!xmqk.getZjly().equals("")){//资金批复类别
			
		}
		try {
			Document document=DocumentHelper.createDocument();
			Element fwlistElement =document.addElement("xmqkList");
			st =conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			rs=st.executeQuery(sql.toString());
			Element fwElement;
			int i=0;
			DecimalFormat df=new DecimalFormat("0.00");
			while(rs.next())
			{	///对承担单位进行判断
				///modefy by cuiyi 20130914 项目承担单位直接输入 不从单位表中获取
				/*String xmqk01009Name = getXmcddw(xmqk.getXmqk01009(), rs.getString("xmqk01009"));
				if(xmqk01009Name.equals("")&&(rs.getString("xmqk01009")!=null&&!rs.getString("xmqk01009").equals("")))
					continue;*/
				/*if(!xmqk.getXmqk01009().equals("")&&rs.getString("xmqk01009")==null){
					////承担单位的查询条件不为空 同时本条记录承担单位的id为空  则终止。
					break;
				}*/
				fwElement=fwlistElement.addElement("xmqkInfo");
				fwElement.addAttribute("XMQK01001",rs.getString("xmqk01001"));
				fwElement.addAttribute("XMQK01002",rs.getString("xmqk01002"));
				fwElement.addAttribute("XMQK01003",rs.getString("xmqk01003"));
				fwElement.addAttribute("XMQK01005",rs.getString("xmqk01005"));
				fwElement.addAttribute("XMQK01006",rs.getString("xmqk01006"));
				fwElement.addAttribute("XMQK01009",rs.getString("xmqk01009"));
				fwElement.addAttribute("XMQK01016",rs.getString("xmqk01016"));
				fwElement.addAttribute("XMQK01019",df.format(rs.getDouble("xmqk01019")));
				fwElement.addAttribute("XMQK01119",rs.getString("xmqk01119"));
				
				fwElement.addAttribute("XMQK01136",rs.getString("xmqk01136"));
				fwElement.addAttribute("XMQK01137",rs.getString("xmqk01137"));
				///modefy by cuiyi 20130914 项目承担单位直接输入 不从单位表中获取
				fwElement.addAttribute("XMQK01009Name",rs.getString("xmqk01009"));
				i++;
			}
			fwlistElement.addAttribute("size", String.valueOf(i));
			
			XMLWriter output = new XMLWriter(xmlout);
			output.write(document);
		}catch (Exception e) {
			System.out.println(e);
		}
		return xmlout.toString();
	}
	public String SearchXmqkDetailsById(String id){
		StringWriter xmlout = new StringWriter();
		Document document=DocumentHelper.createDocument();
		conn = JdbcUtil.getConnection();
		ResultSet rsTmp = null;
		String sql = "";
		
		sql = "select * from xmqk01 where xmqk01001="+id;
		DecimalFormat df=new DecimalFormat("0.00");
		try {
			Element fwlistElement = document.addElement("xmqkInfo");
			st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			rs=st.executeQuery(sql.toString());
			Element fwElement;
			Element subFwElement;
			if(rs.next()){
				fwElement=fwlistElement.addElement("xmqkBaseInfo");
				fwElement.addAttribute("XMQK01001",rs.getString("xmqk01001")==null?"":rs.getString("xmqk01001"));
				fwElement.addAttribute("XMQK01002",rs.getString("xmqk01002")==null?"":rs.getString("xmqk01002"));
				fwElement.addAttribute("XMQK01003",rs.getString("xmqk01003")==null?"":rs.getString("xmqk01003"));
				fwElement.addAttribute("XMQK01004",rs.getString("xmqk01004")==null?"":rs.getString("xmqk01004"));
				fwElement.addAttribute("XMQK01005",rs.getString("xmqk01005")==null?"":rs.getString("xmqk01005"));
				fwElement.addAttribute("XMQK01006",rs.getString("xmqk01006")==null?"":rs.getString("xmqk01006"));
				fwElement.addAttribute("XMQK01007",rs.getString("xmqk01007")==null?"":rs.getString("xmqk01007"));
				fwElement.addAttribute("XMQK01008",rs.getString("xmqk01008")==null?"":rs.getString("xmqk01008"));
				/////////项目批准getXmcddw
				///modefy by cuiyi 20130914 项目批准单位直接输入 不从单位表中获取
				//fwElement.addAttribute("XMQK01008Name",getXmcddw("", rs.getString("xmqk01008")));
				fwElement.addAttribute("XMQK01008Name",rs.getString("xmqk01008")==null?"":rs.getString("xmqk01008"));
				
				//////项目承担单位名称
				///modefy by cuiyi 20130914 项目承担单位直接输入 不从单位表中获取
				//String xmqk01009Name = getXmcddw("", rs.getString("xmqk01009"));
				String xmqk01009Name = rs.getString("xmqk01009")==null?"":rs.getString("xmqk01009");
				fwElement.addAttribute("XMQK01009",rs.getString("xmqk01009")==null?"":rs.getString("xmqk01009"));
				fwElement.addAttribute("XMQK01009Name",xmqk01009Name);
				
				fwElement.addAttribute("XMQK01010",rs.getString("xmqk01010")==null?"":rs.getString("xmqk01010"));
				//fwElement.addAttribute("XMQK01011",rs.getString("xmqk01011")==null?"":rs.getString("xmqk01011"));
				//fwElement.addAttribute("XMQK01012",rs.getString("xmqk01012")==null?"":rs.getString("xmqk01012"));//招投标代理机构
				//fwElement.addAttribute("XMQK01013",rs.getString("xmqk01013"));//招投标代理机构资质
				
				//String tmp = rs.getString("XMQK01012")==null?"":rs.getString("XMQK01012");
				//int cjdw01Int = getInteger(tmp);
				//String[] ztbUnit = getUnitInfo(tmp, "招投标");
				//fwElement.addAttribute("XMQK01012Name",ztbUnit[0]);
				//fwElement.addAttribute("XMQK01013",ztbUnit[1]);
				
				fwElement.addAttribute("XMQK01014",rs.getString("xmqk01014")==null?"":rs.getString("xmqk01014"));
				fwElement.addAttribute("XMQK01015",rs.getString("xmqk01015")==null?"":rs.getString("xmqk01015"));
				fwElement.addAttribute("XMQK01016",rs.getString("xmqk01016")==null?"":rs.getString("xmqk01016"));
				fwElement.addAttribute("XMQK01017",rs.getString("xmqk01017")==null?"":df.format(rs.getDouble("xmqk01017")));
				fwElement.addAttribute("XMQK01018",rs.getString("xmqk01018")==null?"":df.format(rs.getDouble("xmqk01018")));
				fwElement.addAttribute("XMQK01019",rs.getString("xmqk01019")==null?"":df.format(rs.getDouble("xmqk01019")));
				fwElement.addAttribute("XMQK01118",rs.getString("xmqk01118")==null?"":rs.getString("xmqk01118"));
				fwElement.addAttribute("XMQK01119",rs.getString("xmqk01119")==null?"":rs.getString("xmqk01119"));
				fwElement.addAttribute("XMQK01120",rs.getString("xmqk01120")==null?"":rs.getString("xmqk01120"));
				fwElement.addAttribute("XMQK01121",rs.getString("xmqk01121")==null?"":rs.getString("xmqk01121"));
				fwElement.addAttribute("XMQK01122",rs.getString("xmqk01122")==null?"":rs.getString("xmqk01122"));
				fwElement.addAttribute("XMQK01123",rs.getString("xmqk01123")==null?"":rs.getString("xmqk01123"));
				fwElement.addAttribute("XMQK01124",rs.getString("xmqk01124")==null?"":rs.getString("xmqk01124"));
				fwElement.addAttribute("XMQK01125",rs.getString("xmqk01125")==null?"":rs.getString("xmqk01125"));
				fwElement.addAttribute("XMQK01126",rs.getString("xmqk01126")==null?"":rs.getString("xmqk01126"));
				fwElement.addAttribute("XMQK01127",rs.getString("xmqk01127")==null?"":rs.getString("xmqk01127"));
				fwElement.addAttribute("XMQK01128",rs.getString("xmqk01128")==null?"":rs.getString("xmqk01128"));
				fwElement.addAttribute("XMQK01129",rs.getString("xmqk01129")==null?"":rs.getString("xmqk01129"));
				fwElement.addAttribute("XMQK01130",rs.getString("xmqk01130")==null?"":rs.getString("xmqk01130"));
				fwElement.addAttribute("XMQK01131",rs.getString("xmqk01131")==null?"":rs.getString("xmqk01131"));
				fwElement.addAttribute("XMQK01132",rs.getString("xmqk01132")==null?"":rs.getString("xmqk01132"));
				fwElement.addAttribute("XMQK01133",rs.getString("xmqk01133")==null?"":df.format(rs.getDouble("xmqk01133")));
				fwElement.addAttribute("XMQK01134",rs.getString("xmqk01134")==null?"":df.format(rs.getDouble("xmqk01134")));
				fwElement.addAttribute("XMQK01135",rs.getString("xmqk01135")==null?"":rs.getString("xmqk01135"));
				fwElement.addAttribute("XMQK01136",rs.getString("xmqk01136")==null?"":rs.getString("xmqk01136"));
				fwElement.addAttribute("XMQK01137",rs.getString("xmqk01137")==null?"":rs.getString("xmqk01137"));
				fwElement.addAttribute("XMQK01138",rs.getString("xmqk01138")==null?"":rs.getString("xmqk01138"));
				fwElement.addAttribute("XMQK01139",rs.getString("xmqk01139")==null?"":rs.getString("xmqk01139"));
				fwElement.addAttribute("XMQK01140",rs.getString("xmqk01140")==null?"":rs.getString("xmqk01140"));
				/////////////资金批复结果列表
				sql = "select * from zjpf01 where zjpf0102 ="+id;
				st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
				rs=st.executeQuery(sql);
				fwElement=fwlistElement.addElement("zjpfList");
				
				rs.last();
				if(rs.getRow()>0){
					fwElement.addAttribute("size",String.valueOf(rs.getRow()));
					rs.beforeFirst();
					while(rs.next()){
						subFwElement=fwElement.addElement("zjpfInfo");
						//System.out.println(rs.getString("ZJPF0105"));
						subFwElement.addAttribute("ZJPF0101",rs.getString("ZJPF0101")==null?"0":rs.getString("zjpf0101"));
						subFwElement.addAttribute("ZJPF0102",rs.getString("zjpf0102")==null?"0":rs.getString("zjpf0102"));
						subFwElement.addAttribute("ZJPF0103",rs.getString("zjpf0103")==null?"":rs.getString("zjpf0103"));
						subFwElement.addAttribute("ZJPF0104",rs.getString("zjpf0104")==null?"":rs.getString("zjpf0104"));
						subFwElement.addAttribute("ZJPF0105",rs.getString("zjpf0105")==null?"":df.format(rs.getDouble("zjpf0105")));
						subFwElement.addAttribute("ZJPF0106",rs.getString("ZJPF0106")==null?"":rs.getString("zjpf0106"));
						subFwElement.addAttribute("ZJPF0107",rs.getString("zjpf0107")==null?"":rs.getString("zjpf0107"));
					}
				}else{
					fwElement.addAttribute("size","0");
				}
				/////////////参建单位结果列表
				sql = "select * from cjdw01,dwqk01,dwzz01 where cjdw0103=dwqk0101 and cjdw0104=dwzz0104 and dwzz0102=dwqk0101 and cjdw0102 ="+id;
				st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
				rs=st.executeQuery(sql);
				fwElement=fwlistElement.addElement("cjdwList");
				rs.last();
				if(rs.getRow()>0){
					String[] unitObj = null;
					String[] ztbUnit = null;
					int cjdw01Int = 0;
					fwElement.addAttribute("size",String.valueOf(rs.getRow()));
					rs.beforeFirst();
					
					while(rs.next()){
						/////////没有对招投标代理机构判别  只有编号  没有名称和资质
						subFwElement=fwElement.addElement("cjdwInfo");
						subFwElement.addAttribute("CJDW0101",rs.getString("CJDW0101")==null?"0":rs.getString("CJDW0101"));
						subFwElement.addAttribute("CJDW0102",rs.getString("CJDW0102")==null?"0":rs.getString("CJDW0102"));
						////参建单位名称和资质级别
						subFwElement.addAttribute("CJDW0103",rs.getString("CJDW0103")==null?"":rs.getString("CJDW0103"));
						//subFwElement.addAttribute("CJDW0103Name",rs.getString("DWQK0103")==null?"":rs.getString("DWQK0103"));
						//subFwElement.addAttribute("CJDW0103ZZ",rs.getString("DWZZ0105")==null?"":rs.getString("DWZZ0105"));
						String cjtype = rs.getString("CJDW0104")==null?"":commUtils.parseForCjdwName(rs.getString("CJDW0104"));
						subFwElement.addAttribute("CJDW0104",cjtype);
						subFwElement.addAttribute("CJDW0105",rs.getString("CJDW0105")==null?"":rs.getString("CJDW0105"));
						subFwElement.addAttribute("CJDW0106",rs.getString("CJDW0106")==null?"":rs.getString("CJDW0106"));
						subFwElement.addAttribute("CJDW0107",rs.getString("CJDW0107")==null?"":rs.getString("CJDW0107"));
						subFwElement.addAttribute("CJDW0108",rs.getString("CJDW0108")==null?"0.00":df.format(rs.getDouble("CJDW0108")));
						subFwElement.addAttribute("CJDW0109",rs.getString("CJDW0109")==null?"":rs.getString("CJDW0109"));
						subFwElement.addAttribute("CJDW0110",rs.getString("CJDW0110")==null?"":rs.getString("CJDW0110"));
						subFwElement.addAttribute("CJDW0111",rs.getString("CJDW0111")==null?"":rs.getString("CJDW0111"));
						subFwElement.addAttribute("CJDW0112",rs.getString("CJDW0112")==null?"":rs.getString("CJDW0112"));
						subFwElement.addAttribute("CJDW0113",rs.getString("CJDW0113")==null?"":rs.getString("CJDW0113"));
						subFwElement.addAttribute("CJDW0114",rs.getString("CJDW0114")==null?"":rs.getString("CJDW0114"));
						if(cjtype.equals("可研")||cjtype.equals("监测")){
							subFwElement.addAttribute("CJDW0103Name",rs.getString("CJDW0117")==null?"":rs.getString("CJDW0117"));
							subFwElement.addAttribute("CJDW0103ZZ",rs.getString("CJDW0118")==null?"":rs.getString("CJDW0118"));
						}else{
							subFwElement.addAttribute("CJDW0103Name",rs.getString("dwqk0103")==null?"":rs.getString("dwqk0103"));
							subFwElement.addAttribute("CJDW0103ZZ",rs.getString("dwzz0105"));
						}
						////招投标代理机构查询名称及资质
						///modefy by cuiyi 20130914  参建单位去掉招投标代理机构，只留施工单位 的
						subFwElement.addAttribute("CJDW0106Name",rs.getString("CJDW0115")==null?"":rs.getString("CJDW0105"));
						subFwElement.addAttribute("CJDW0106ZZ",rs.getString("CJDW0116")==null?"":rs.getString("CJDW0116"));
					}
				}else{
					fwElement.addAttribute("size","0");
				}
				/////////////参建单位结果列表
				sql = "select * from cjdw01 where (cjdw0104='可研' or cjdw0104='监测') and cjdw0102 ="+id;
				st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
				rs=st.executeQuery(sql);
				fwElement=fwlistElement.addElement("cjdwList");
				rs.last();
				if(rs.getRow()>0){
					String[] unitObj = null;
					String[] ztbUnit = null;
					int cjdw01Int = 0;
					fwElement.addAttribute("size",String.valueOf(rs.getRow()));
					rs.beforeFirst();
					while(rs.next()){
						/////////没有对招投标代理机构判别  只有编号  没有名称和资质
						subFwElement=fwElement.addElement("cjdwInfo");
						subFwElement.addAttribute("CJDW0101",rs.getString("CJDW0101")==null?"0":rs.getString("CJDW0101"));
						subFwElement.addAttribute("CJDW0102",rs.getString("CJDW0102")==null?"0":rs.getString("CJDW0102"));
						////参建单位名称和资质级别
						subFwElement.addAttribute("CJDW0103",rs.getString("CJDW0103")==null?"":rs.getString("CJDW0103"));
						String cjtype = rs.getString("CJDW0104")==null?"":commUtils.parseForCjdwName(rs.getString("CJDW0104"));
						subFwElement.addAttribute("CJDW0104",cjtype);
						subFwElement.addAttribute("CJDW0105",rs.getString("CJDW0105")==null?"":rs.getString("CJDW0105"));
						subFwElement.addAttribute("CJDW0106",rs.getString("CJDW0106")==null?"":rs.getString("CJDW0106"));
						subFwElement.addAttribute("CJDW0107",rs.getString("CJDW0107")==null?"":rs.getString("CJDW0107"));
						subFwElement.addAttribute("CJDW0108",rs.getString("CJDW0108")==null?"0.00":df.format(rs.getDouble("CJDW0108")));
						subFwElement.addAttribute("CJDW0109",rs.getString("CJDW0109")==null?"":rs.getString("CJDW0109"));
						subFwElement.addAttribute("CJDW0110",rs.getString("CJDW0110")==null?"":rs.getString("CJDW0110"));
						subFwElement.addAttribute("CJDW0111",rs.getString("CJDW0111")==null?"":rs.getString("CJDW0111"));
						subFwElement.addAttribute("CJDW0112",rs.getString("CJDW0112")==null?"":rs.getString("CJDW0112"));
						subFwElement.addAttribute("CJDW0113",rs.getString("CJDW0113")==null?"":rs.getString("CJDW0113"));
						subFwElement.addAttribute("CJDW0114",rs.getString("CJDW0114")==null?"":rs.getString("CJDW0114"));
						subFwElement.addAttribute("CJDW0103Name",rs.getString("CJDW0117")==null?"":rs.getString("CJDW0117"));
						subFwElement.addAttribute("CJDW0103ZZ",rs.getString("CJDW0118")==null?"":rs.getString("CJDW0118"));
						////招投标代理机构查询名称及资质
						///modefy by cuiyi 20130914  参建单位去掉招投标代理机构，只留施工单位 的
						subFwElement.addAttribute("CJDW0106Name",rs.getString("CJDW0115")==null?"":rs.getString("CJDW0105"));
						subFwElement.addAttribute("CJDW0106ZZ",rs.getString("CJDW0116")==null?"":rs.getString("CJDW0116"));
					}
				}else{
					fwElement.addAttribute("size","0");
				}
				/////////////涉及灾害点结果列表
				sql = "select * from zhd01 where zhd01002 ="+id;
				st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
				rs=st.executeQuery(sql);
				fwElement=fwlistElement.addElement("zhdList");
				
				rs.last();
				if(rs.getRow()>0){
					fwElement.addAttribute("size",String.valueOf(rs.getRow()));
					rs.beforeFirst();
					while(rs.next()){
						subFwElement=fwElement.addElement("zhdInfo");
						//System.out.println(rs.getString("ZJPF0105"));
						subFwElement.addAttribute("ZHD01001",rs.getString("ZHD01001")==null?"0":rs.getString("ZHD01001"));
						subFwElement.addAttribute("ZHD01002",rs.getString("ZHD01002")==null?"0":rs.getString("ZHD01002"));
						subFwElement.addAttribute("ZHD01003",rs.getString("ZHD01003")==null?"":rs.getString("ZHD01003"));
						subFwElement.addAttribute("ZHD01004",rs.getString("ZHD01004")==null?"":rs.getString("ZHD01004"));
					}
				}else{
					fwElement.addAttribute("size","0");
				}
			}
			XMLWriter output = new XMLWriter(xmlout);
			output.write(document);
		}catch (Exception e) {
			System.out.println(e);
		}
		return xmlout.toString();
	}
	/**
	 * 2013-6-6
	 * 崔艺  获取项目承担单位
	 * @param xmqk01009  条件
	 * @param xmqk01009value  要匹配的记录
	 * @return
	 */
	private String  getXmcddw(String xmqk01009,String xmqk01009value){
		String cddwName = xmqk01009!=null&&!xmqk01009.equals("")?xmqk01009:"";//项目承担单位名称 模糊匹配
		String subSql = " and dwqk0103 like '%"+cddwName+"%'";
		String tmpDwqk0101 = xmqk01009value==null?"":xmqk01009value;
		int dwqk01Int = getInteger(tmpDwqk0101);
		String sqlTmp= "select * from dwqk01 where   dwqk0101 ='"+dwqk01Int+"'"+subSql;
		try{
			PreparedStatement psTmp = conn.prepareStatement(sqlTmp);
			ResultSet rsTmp=psTmp.executeQuery();
			if(rsTmp.next()){
				return rsTmp.getString("dwqk0103");
			}else{
				return "";
			}
		}catch (Exception e) {
			return "";// TODO: handle exception
		}
		
	}
	/**
	 * 2013-6-8
	 * 崔艺
	 * @param dwid
	 * @param unitType
	 * @return
	 * 根据招投标单位id获得招投标单位的名称和对应的资质
	 */
	private String[] getUnitInfo(String dwid,String unitType){
		String tmpCjdw0106 = dwid==null?"":dwid;
		int cjdw01Int = getInteger(tmpCjdw0106);
		String sql= "select * from dwqk01,dwzz01 where   dwqk0101=dwzz0102 and dwzz0102 ='"+cjdw01Int+"' and dwzz0104='"+unitType+"'";
		try{
			PreparedStatement pst = conn.prepareStatement(sql);
			ResultSet rsTmp=pst.executeQuery();
			if(rsTmp.next()){
				return new String[]{rsTmp.getString("dwqk0103"),unitType+rsTmp.getString("dwzz0105")};
			}else{
				return new String[]{"",""};
			}
		}catch (Exception e) {
			return new String[]{"",""};
		}
	}
	/**
	 * 根据id删除参建单位
	 * 2013-6-14
	 * 崔艺
	 * @param id
	 * @return
	 */
	public boolean deleteCjdwById(String id){
		String sql = "delete from cjdw01 where cjdw0101="+id;
		return JdbcUtil.executeSql(sql)>0?true:false;
	}
	/* 2013-6-14下午10:11:51
	 * auther:cuiyi 
	 * 根据id删除资金批复
	 */
	public boolean deleteZjpfById(String id){
		String sql = "delete from zjpf01 where zjpf0101="+id;
		return JdbcUtil.executeSql(sql)>0?true:false;
	}
	public boolean deleteZhdById(String id){
		String sql = "delete from zhd01 where zhd01001="+id;
		return JdbcUtil.executeSql(sql)>0?true:false;
	}
	/**
	 * 更新项目基本情况及资金批复和参建单位
	 * 2013-6-14
	 * 崔艺
	 * @param xmqk01
	 * @param zjpfList
	 * @param cjdwList
	 * @return
	 */
	public boolean updateXmqk01ForOneToMany(Xmqk01New xmqk01,List<Zjpf01> zjpfList,List<Cjdw01> cjdwList,List<ZHD01> zhdList){
		 conn=JdbcUtil.getConnection();
		 String sql = "";
		 sql = "update xmqk01 set  xmqk01002=?,xmqk01003 =?,xmqk01004=?,xmqk01005=?,xmqk01006=?,xmqk01007=?,xmqk01008=?,xmqk01009=?,xmqk01010=?," +
	   		"xmqk01011=?,xmqk01012=?,xmqk01013=?,xmqk01014=?,xmqk01015=?,xmqk01016=?,xmqk01017=?,xmqk01018 =?,xmqk01019=?," +
	   		"xmqk01118 =?,xmqk01119=?,xmqk01120=?," +
	   		"xmqk01121=?,xmqk01122=?,xmqk01123=?,xmqk01124=?,xmqk01125=?,xmqk01126=?,xmqk01127=?,xmqk01128=?,xmqk01129=?,xmqk01130=?," +
	   		"xmqk01131=?,xmqk01132=?,xmqk01133=?,xmqk01134=?,xmqk01135 =?,xmqk01136=?,xmqk01137=?,xmqk01138=?,xmqk01139=?,xmqk01140=?  where xmqk01001=?";
	
			try {
				ps = conn.prepareStatement(sql);
				ps.setString(1, xmqk01.getXMQK01002());
				ps.setString(2, xmqk01.getXMQK01003());
				ps.setString(3, xmqk01.getXMQK01004());
				ps.setString(4, xmqk01.getXMQK01005());
				ps.setString(5, xmqk01.getXMQK01006());
				ps.setString(6, xmqk01.getXMQK01007());
				ps.setString(7, xmqk01.getXMQK01008());
				ps.setString(8, xmqk01.getXMQK01009());
				ps.setString(9, xmqk01.getXMQK01010());
				ps.setString(10,xmqk01.getXMQK01011());
				ps.setString(11,xmqk01.getXMQK01012());
				ps.setString(12,xmqk01.getXMQK01013());
				ps.setString(13,xmqk01.getXMQK01014());
				ps.setString(14,xmqk01.getXMQK01015());
				ps.setString(15,xmqk01.getXMQK01016());
				ps.setDouble(16,xmqk01.getXMQK01017()==null?Double.valueOf("0"):xmqk01.getXMQK01017());
				ps.setDouble(17,xmqk01.getXMQK01018()==null?Double.valueOf("0"):xmqk01.getXMQK01018());
				ps.setDouble(18,xmqk01.getXMQK01019()==null?Double.valueOf("0"):xmqk01.getXMQK01019());
				
				ps.setString(19,xmqk01.getXMQK01118());
				ps.setString(20,xmqk01.getXMQK01119());
				ps.setString(21,xmqk01.getXMQK01120());
				ps.setString(22,xmqk01.getXMQK01121());
				ps.setString(23,xmqk01.getXMQK01122());
				ps.setString(24,xmqk01.getXMQK01123());
				ps.setString(25,xmqk01.getXMQK01124());
				ps.setString(26,xmqk01.getXMQK01125());
				ps.setString(27,xmqk01.getXMQK01126());
				ps.setString(28,xmqk01.getXMQK01127());
				
				ps.setInt(29, xmqk01.getXMQK01128()==null?0:xmqk01.getXMQK01128());
				ps.setInt(30, xmqk01.getXMQK01129()==null?0:xmqk01.getXMQK01129());
				ps.setInt(31, xmqk01.getXMQK01130()==null?0:xmqk01.getXMQK01130());
				ps.setInt(32, xmqk01.getXMQK01131()==null?0:xmqk01.getXMQK01131());
				ps.setString(33,xmqk01.getXMQK01132());
				ps.setDouble(34, xmqk01.getXMQK01133()==null?Double.valueOf("0"):xmqk01.getXMQK01133());
				ps.setDouble(35, xmqk01.getXMQK01134()==null?Double.valueOf("0"):xmqk01.getXMQK01134());
				ps.setString(36,xmqk01.getXMQK01135());
				ps.setString(37,xmqk01.getXMQK01136());
				ps.setString(38,xmqk01.getXMQK01137());
				ps.setString(39,xmqk01.getXMQK01138());
				ps.setDouble(40,xmqk01.getXMQK01139()==null?Double.valueOf("0"):xmqk01.getXMQK01139());
				ps.setDouble(41,xmqk01.getXMQK01140()==null?Double.valueOf("0"):xmqk01.getXMQK01140());
				ps.setInt(42, xmqk01.getXMQK01001());
				int number=ps.executeUpdate();
				if(number>0)///项目更新成功
				{
					
					int xmId = xmqk01.getXMQK01001();
					//////资金批复录入
					for(int i =0;zjpfList!=null&&i<zjpfList.size();i++){
						
						Zjpf01 zjpf = (Zjpf01)zjpfList.get(i);
						if(zjpf.getZJPF0101()==0){///资金批复ID为0  说明为新增的资金批复
							sql = "insert into zjpf01 values(oa_seq.nextval,?,?,?,?,?,?)";
							ps = conn.prepareStatement(sql);
							ps.setInt(1, xmId);
							ps.setString(2, zjpf.getZJPF0103());
							ps.setString(3, zjpf.getZJPF0104());
							ps.setDouble(4, zjpf.getZJPF0105());
							ps.setString(5, zjpf.getZJPF0106());
							ps.setString(6, zjpf.getZJPF0107());
							number=ps.executeUpdate();
							if(!(number>0)){//资金批复插入失败。数据库回滚，删除之前所有数据。
								System.out.println("资金批复更新失败（新增）");
							}
						}else{
							sql = "update zjpf01 set zjpf0102=?,zjpf0103=?,zjpf0104=?,zjpf0105=?,zjpf0106=?,zjpf0107=? where zjpf0101=?";
							ps = conn.prepareStatement(sql);
							ps.setInt(1, zjpf.getZJPF0102());
							ps.setString(2, zjpf.getZJPF0103());
							ps.setString(3, zjpf.getZJPF0104());
							ps.setDouble(4, zjpf.getZJPF0105());
							ps.setString(5, zjpf.getZJPF0106());
							ps.setString(6, zjpf.getZJPF0107());
							ps.setInt(7, zjpf.getZJPF0101());
							number=ps.executeUpdate();
							if(!(number>0)){//资金批复更新失败。数据库回滚，删除之前所有数据。
								System.out.println("资金批复更新失败（更新）");
							}
						}
						
					}
					///参建单位录入
					for(int i=0;cjdwList!=null&&i<cjdwList.size();i++){
						
						Cjdw01 cjdw = (Cjdw01)cjdwList.get(i);
						if(cjdw.getCJDW0104().equals("B")||cjdw.getCJDW0104().equals("F")){///可研或者监测输入单位名称为空时，忽略掉此记录
							if(cjdw.getCJDW0117()==null||cjdw.getCJDW0117().equals("")){
								continue;
							}
						}else if(cjdw.getCJDW0103()==0){///单位名称未选择时，忽略掉此记录
							continue;
						}
						if(cjdw.getCJDW0101()==0){
							sql = "insert into cjdw01 values(oa_seq.nextval,?,?,?,?,?," +
							"?,?,?,?,?," +
							"?,?,?,?,?," +
							"?,?)";
							ps = conn.prepareStatement(sql);
							ps.setInt(1, xmId);
							ps.setInt(2, cjdw.getCJDW0103());
							ps.setString(3, commUtils.parseForCjdwType(cjdw.getCJDW0104()));
							ps.setString(4, cjdw.getCJDW0105());
							ps.setString(5, cjdw.getCJDW0106());
							ps.setString(6, cjdw.getCJDW0107());
							ps.setDouble(7, cjdw.getCJDW0108());
							ps.setString(8, cjdw.getCJDW0109());
							ps.setString(9, cjdw.getCJDW0110());
							ps.setString(10, cjdw.getCJDW0111());
							ps.setString(11, cjdw.getCJDW0112());
							ps.setString(12, cjdw.getCJDW0113());
							ps.setString(13, cjdw.getCJDW0114());
							ps.setString(14, cjdw.getCJDW0115());
							ps.setString(15, cjdw.getCJDW0116());
							ps.setString(16, cjdw.getCJDW0117());
							ps.setString(17, cjdw.getCJDW0118());
							number=ps.executeUpdate();
							if(!(number>0)){//参建单位插入失败。数据库回滚，删除之前所有数据。
								System.out.println("参建单位录入失败(新增)");
								return false;
							}
						}else{
							sql = "update cjdw01 set cjdw0102=?,cjdw0103=?,cjdw0104=?,cjdw0105=?," +
									"cjdw0106=?,cjdw0107=?,cjdw0108=?,cjdw0109=?,cjdw0110=?," +
									"cjdw0111=?,cjdw0112=?,cjdw0113=?,cjdw0114=?,cjdw0115=?," +
									"cjdw0116=?,cjdw0117=?,cjdw0118=?  where cjdw0101=?";
							ps = conn.prepareStatement(sql);
							ps.setInt(1, cjdw.getCJDW0102());
							ps.setInt(2, cjdw.getCJDW0103());
							ps.setString(3, commUtils.parseForCjdwType(cjdw.getCJDW0104()));
							ps.setString(4, cjdw.getCJDW0105());
							ps.setString(5, cjdw.getCJDW0106());
							ps.setString(6, cjdw.getCJDW0107());
							ps.setDouble(7, cjdw.getCJDW0108());
							ps.setString(8, cjdw.getCJDW0109());
							ps.setString(9, cjdw.getCJDW0110());
							ps.setString(10, cjdw.getCJDW0111());
							ps.setString(11, cjdw.getCJDW0112());
							ps.setString(12, cjdw.getCJDW0113());
							ps.setString(13, cjdw.getCJDW0114());
							ps.setString(14, cjdw.getCJDW0115());
							ps.setString(15, cjdw.getCJDW0116());
							ps.setString(16, cjdw.getCJDW0117());
							ps.setString(17, cjdw.getCJDW0118());
							ps.setInt(18, cjdw.getCJDW0101());
							number=ps.executeUpdate();
							if(!(number>0)){//参建单位录入失败(更新)
								System.out.println("参建单位录入失败(更新)");
							}
						}
						
					}
					//////灾害点信息更新
					for(int i =0;zhdList!=null&&i<zhdList.size();i++){
						
						ZHD01 zhd = (ZHD01)zhdList.get(i);
						if(zhd.getZHD01001()==0){///灾害点的ID为0  说明为新增的灾害点
							sql = "insert into zhd01 values(oa_seq.nextval,?,?,?)";
							ps = conn.prepareStatement(sql);
							ps.setInt(1, xmId);
							ps.setString(2, zhd.getZHD01003());
							ps.setString(3, zhd.getZHD01004());
							number=ps.executeUpdate();
							if(!(number>0)){//灾害点插入失败。数据库回滚，删除之前所有数据。
								System.out.println("灾害点更新失败（新增）");
							}
						}else{
							sql = "update zhd01 set zhd01002=?,zhd01003=?,zhd01004=? where zhd01001=?";
							ps = conn.prepareStatement(sql);
							ps.setInt(1, zhd.getZHD01002());
							ps.setString(2, zhd.getZHD01003());
							ps.setString(3, zhd.getZHD01004());
							ps.setInt(4, zhd.getZHD01001());
							number=ps.executeUpdate();
							if(!(number>0)){//资金批复更新失败。数据库回滚，删除之前所有数据。
								System.out.println("灾害点更新失败（更新）");
							}
						}
					}
					/////////更新项目总费用字段
					sql = "update xmqk01 set xmqk01019=(select sum(zjpf0105) from zjpf01 where zjpf0102="+xmId+") where xmqk01001 ="+xmId;
					ps = conn.prepareStatement(sql);
					number = ps.executeUpdate();
				}else{///项目录入失败
					System.out.println( "项目更新失败");
					return false;
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
				System.out.println( "项目更新失败");
				return false;
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return true;
	}
	public List<Xmfj01> SearchXmfj(String xmName,String  fjName,String wdType,String wdsubType){
		List<Xmfj01> xmfj01List=new ArrayList<Xmfj01>();
		conn=JdbcUtil.getConnection();
		String PWsql = "select zjpf0101 as xmId,xmqk01002 as xmCode, xmqk01003 as xmName,zjpf0106 as fjUrl,zjpf0103 as subType,zjpf0104 as pfYear from xmqk01,zjpf01 where zjpf0102=xmqk01001 and xmqk01003 like '%"+xmName+"%' and zjpf0106 like '%"+fjName+"%'";
		///需要处理查出结果  附件名称匹配
		String CJDWsql = "select cjdw0101 as xmId,xmqk01002 as xmCode, xmqk01003 as xmName,cjdw0111 ,cjdw0112,cjdw0113,cjdw0104 as type,dwqk0103 " +
				"from xmqk01,cjdw01,dwqk01,dwzz01 where xmqk01001 = cjdw0102 and cjdw0103=dwqk0101 and cjdw0104=dwzz0104 and dwzz0102=dwqk0101 and xmqk01003 like '%"+xmName+"%' ";
		String JGsql = "select xmqk01001 as xmId,xmqk01002 as xmCode,xmqk01003 as xmName,xmqk01122,xmqk01123,xmqk01126,xmqk01127 from xmqk01 where xmqk01003 like '%"+xmName+"%' ";
		conn = JdbcUtil.getConnection();
		try{
			if(wdType.equals("0")){///所有类别的文档
				//////////////////批文
				ps = conn.prepareStatement(PWsql);
				rs=ps.executeQuery();
				while(rs.next()){
					xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),"PW","PW"+commUtils.parseForZjpfTypeCode(rs.getString("subType")), rs.getString("fjUrl"),"批复年度"+rs.getString("pfYear"),fjName));
				}
				////////////////参建单位
				//String type = commUtils.parseForCjdwName(wdType);
				//CJDWsql +=" and cjdw0104='"+type+"'";
				ps = conn.prepareStatement(CJDWsql);
				rs=ps.executeQuery();
				while(rs.next()){
					xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),commUtils.parseForCjdwTypeByName(rs.getString("type")),commUtils.parseForCjdwTypeByName(rs.getString("type"))+"00", rs.getString("cjdw0111"),"参建单位"+rs.getString("dwqk0103"),fjName));
					xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),commUtils.parseForCjdwTypeByName(rs.getString("type")),commUtils.parseForCjdwTypeByName(rs.getString("type"))+"01", rs.getString("cjdw0112"),"参建单位"+rs.getString("dwqk0103"),fjName));
					xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),commUtils.parseForCjdwTypeByName(rs.getString("type")),commUtils.parseForCjdwTypeByName(rs.getString("type"))+"02", rs.getString("cjdw0113"),"参建单位"+rs.getString("dwqk0103"),fjName));
				}
				//////////////竣工
				ps = conn.prepareStatement(JGsql);
				rs=ps.executeQuery();
				while(rs.next()){
					xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),"JG","JG"+"00", rs.getString("xmqk01122"),"",fjName));
					xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),"JG","JG"+"01", rs.getString("xmqk01123"),"",fjName));
					xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),"JG","JG"+"02", rs.getString("xmqk01126"),"",fjName));
					xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),"JG","JG"+"03", rs.getString("xmqk01127"),"",fjName));
				}
			}else{
				switch(wdfjTypeEnum.valueOf(wdType)){
				case PW://批文   PW
					ps = conn.prepareStatement(PWsql);
					rs=ps.executeQuery();
					while(rs.next()){
						xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),wdType,wdType+commUtils.parseForZjpfTypeCode(rs.getString("subType")), rs.getString("fjUrl"),"批复年度"+rs.getString("pfYear"),fjName));
					}
					break;
				case KY://可研  KY
				case KC://勘察  KC
				case SJ://设计  SJ
				case SG://施工  SG
				case JL://监理  JL
				case JC://监测  JC
					//String type = commUtils.parseForCjdwName(wdType);
					//CJDWsql +=" and cjdw0104='"+type+"'";
					ps = conn.prepareStatement(CJDWsql);
					rs=ps.executeQuery();
					while(rs.next()){
						xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),wdType,wdType+"00", rs.getString("cjdw0111"),"参建单位"+rs.getString("dwqk0103"),fjName));
						xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),wdType,wdType+"01", rs.getString("cjdw0112"),"参建单位"+rs.getString("dwqk0103"),fjName));
						xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),wdType,wdType+"02", rs.getString("cjdw0113"),"参建单位"+rs.getString("dwqk0103"),fjName));
					}
					break;
				case JG://竣工  JG
					ps = conn.prepareStatement(JGsql);
					rs=ps.executeQuery();
					while(rs.next()){
						xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),wdType,wdType+"00", rs.getString("xmqk01122"),"",fjName));
						xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),wdType,wdType+"01", rs.getString("xmqk01123"),"",fjName));
						xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),wdType,wdType+"02", rs.getString("xmqk01126"),"",fjName));
						xmfj01List.add(getXmfjObj(rs.getInt("xmId"),rs.getString("xmCode"),rs.getString("xmName"),wdType,wdType+"03", rs.getString("xmqk01127"),"",fjName));
					}
					break;	
				}
			}
		}catch (SQLException e) {
			e.printStackTrace();
			System.out.println( "项目附件查询失败");
		} finally
		{
			JdbcUtil.closeAll(ps,conn);
		}
	
		return xmfj01List;
	}
	private Xmfj01 getXmfjObj(int xmId,String xmCode,String xmName,String fjType,String fjSubType,String fjUrl,String remark,String fjName){
		Xmfj01 xmfj = new Xmfj01();
		if((fjUrl!=null&&fjUrl.indexOf(fjName)>-1)||(fjUrl==null&&fjName.equals(""))){
			xmfj.setXmfj0101(xmId);
			xmfj.setXmfj0102(xmCode);
			xmfj.setXmfj0103(xmName);
			xmfj.setXmfj0104(fjType);
			xmfj.setXmfj0105(fjSubType);
			xmfj.setXmfj0106(fjUrl);
			xmfj.setXmfj0107(remark);
		}
		return xmfj;
	}
	//项目名称、项目年度、项目类型、项目子类型、项目所在市、项目所在区/县、承担单位
	public String statXmqk01(xmqkQueryObj xmqk){
		StringWriter xmlout = new StringWriter();
		conn = JdbcUtil.getConnection();
		StringBuffer sql = new StringBuffer();
		StringBuffer connSql = new StringBuffer();
		if(!xmqk.getXmqk01009().equals("")){//项目承担单位
			sql.append("from xmqk01,dwqk01,zjpf01 where " +
			"xmqk01009=dwqk0101 and xmqk01001=zjpf0102 and dwqk0103 like '%"+xmqk.getXmqk01009()+"%'");
		}else{
			sql.append("from xmqk01,zjpf01 where  xmqk01001=zjpf0102");
		}
		/////统计条件
		if (!xmqk.getXmqk01003().equals("")) {//项目名称
			connSql.append(" and xmqk01003 like '%" + xmqk.getXmqk01003() + "%'");
		}
		if (!xmqk.getXmqk0105s().equals("")) {//项目年度起
			connSql.append(" and xmqk01005 >='" + xmqk.getXmqk0105s() + "'");
		}
		if (!xmqk.getXmqk0105e().equals("")) {//项目年度止
			connSql.append(" and xmqk01005 <'" + xmqk.getXmqk0105e() + "'");
		}
		if (!xmqk.getXmqk01006().equals("")) {//项目类型和子类型
			connSql.append(" and xmqk01006 ='" + xmqk.getXmqk01006() + "'");
		}
		if(!xmqk.getXmqk01136().equals("")){//项目所在市
			connSql.append(" and xmqk01136 ='"+xmqk.getXmqk01136()+"'");
		}
		if(!xmqk.getXmqk01137().equals("")){//项目所在县
			connSql.append(" and xmqk01137 ='"+xmqk.getXmqk01137()+"'");
		}
		sql.append(connSql);
		String statSql =  "";
		Element fwElement;
		Element subElement;
		Element threeElement;
		Element fourElement;
		Element oneWxdxElement;
		Element oneWxzcElement;
		Element twoWxdxElement;
		Element twoWxzcElement;
		Element threeWxdxElement;
		Element threeWxzcElement;
		Element fourWxdxElement;
		Element fourWxzcElement;
		DecimalFormat df=new DecimalFormat("0.00");
		double sum=0;
		try {
			Document document=DocumentHelper.createDocument();
			st = conn.createStatement();
			Element fwlistElement =document.addElement("statRes");
			////资金批复统计
			///资金批复按年度统计
			statSql ="select zjpf0104,sum(zjpf0105) as zjpf0105 "+sql.toString()+" group by zjpf0104 order by zjpf0104";
			rs=st.executeQuery(statSql);
			fwElement=fwlistElement.addElement("zjpfStat");
			oneWxdxElement=fwlistElement.addElement("wxdxStat");
			oneWxzcElement=fwlistElement.addElement("wxzcStat");
			subElement = fwElement.addElement("zjpfStatByYear");
			while(rs.next())
			{
				if(rs.getString("zjpf0104")==null||rs.getString("zjpf0104").equals(""))
					continue;
				threeElement = subElement.addElement("zjpfStatByYearObj");
				
				threeElement.addAttribute("label",rs.getString("zjpf0104"));
				threeElement.addAttribute("value",df.format(rs.getDouble("zjpf0105")));
				sum +=rs.getDouble("zjpf0105");
			}
			fwElement.addAttribute("sum", String.valueOf(sum));
			///资金批复按类别统计
			sum = 0;
			statSql ="select zjpf0103,sum(zjpf0105) as zjpf0105 "+sql.toString()+" group by zjpf0103 order by zjpf0103";
			rs=st.executeQuery(statSql);
			subElement = fwElement.addElement("zjpfStatByType");
			while(rs.next()){
				threeElement = subElement.addElement("zjpfStatByTypeObj");
				threeElement.addAttribute("label",commUtils.parseForZjpfNameByCode(rs.getString("zjpf0103")));
				threeElement.addAttribute("value",df.format(rs.getDouble("zjpf0105")));
				//sum +=rs.getDouble("zjpf0105");
			}
			//fwElement.addAttribute("zjpfStatByTypeSum", String.valueOf(sum));
			////资金批复组合统计
			statSql = "select distinct xmqk01005 " +sql.toString()+" order by xmqk01005";///先检索出年份
			rs=st.executeQuery(statSql);
			ResultSet subrs = null;
			Statement subst = null;
			subst = conn.createStatement();
			subElement = fwElement.addElement("zjpfStatByAll");
			while(rs.next()){
				String year = rs.getString("xmqk01005");
				if(year==null||year.equals("")||year.equals("请选择"))
					continue;
				statSql = "select zjpf0103,sum(zjpf0105) as zjpf0105 from xmqk01,zjpf01 where xmqk01001=zjpf0102 and xmqk01005='"+year+"' group by zjpf0103 order by zjpf0103";
				subrs =subst.executeQuery(statSql);
				threeElement = subElement.addElement("zjpfStatByAllYear");
				threeElement.addAttribute("year",year);
				while(subrs.next()){
					/*fourElement = threeElement.addElement("zjpfStatByAllYearObj");
					fourElement.addAttribute("label",commUtils.parseForZjpfTypeCode(subrs.getString("zjpf0103")));
					fourElement.addAttribute("value",df.format(subrs.getDouble("zjpf0105")));*/
					//threeElement.addAttribute(commUtils.parseForZjpfNameByCode(subrs.getString("zjpf0103")),df.format(subrs.getDouble("zjpf0105")));
					threeElement.addAttribute(subrs.getString("zjpf0103"),df.format(subrs.getDouble("zjpf0105")));
				}
				
				/////统计威胁对象和威胁资产。
				statSql = "select sum(xmqk01128) as xmqk01128,sum(xmqk01129) as xmqk01129,sum(xmqk01130) as xmqk01130,sum(xmqk01131) as xmqk01131,sum(xmqk01133) as xmqk01133,sum(xmqk01134) as xmqk01134 " +
						"from xmqk01 where xmqk01005='"+year+"' "+connSql.toString();
				subrs =subst.executeQuery(statSql);
				twoWxdxElement = oneWxdxElement.addElement("wxdxStatByYearObj");
				twoWxzcElement = oneWxzcElement.addElement("wxzcStatByYearObj");
				twoWxdxElement.addAttribute("year",year);
				twoWxzcElement.addAttribute("year",year);
				while(subrs.next()){
					twoWxdxElement.addAttribute("xmqk01128", subrs.getString("xmqk01128"));
					twoWxdxElement.addAttribute("xmqk01129", subrs.getString("xmqk01129"));
					twoWxdxElement.addAttribute("xmqk01130", subrs.getString("xmqk01130"));
					twoWxdxElement.addAttribute("xmqk01131", subrs.getString("xmqk01131"));
					twoWxzcElement.addAttribute("xmqk01133", subrs.getString("xmqk01133"));
					twoWxzcElement.addAttribute("xmqk01134", subrs.getString("xmqk01134"));
				}
				
			}
			XMLWriter output = new XMLWriter(xmlout);
			output.write(document);
		}catch (Exception e) {
			System.out.println(e);
		}
		return xmlout.toString();
	}
}
